Browse Source

Fix #1828, Fix #2290: Ensure base references have the correct type and are turned into this references and casted if necessary

pull/2315/head
Siegfried Pammer 4 years ago
parent
commit
280a94ce5d
  1. 4
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 8
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

4
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2487,9 +2487,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2487,9 +2487,11 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (ShouldUseBaseReference())
{
var baseReferenceType = resolver.CurrentTypeDefinition.DirectBaseTypes
.FirstOrDefault(t => t.Kind != TypeKind.Interface);
return new BaseReferenceExpression()
.WithILInstruction(target)
.WithRR(new ThisResolveResult(memberDeclaringType, nonVirtualInvocation));
.WithRR(new ThisResolveResult(baseReferenceType ?? memberDeclaringType, nonVirtualInvocation));
}
else
{

8
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -452,6 +452,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -452,6 +452,7 @@ namespace ICSharpCode.Decompiler.CSharp
// perform remaining pointer cast, if necessary
return pointerExpr.ConvertTo(targetType, expressionBuilder);
}
Expression expr;
if (targetType.Kind == TypeKind.ByReference)
{
if (NormalizeTypeVisitor.TypeErasure.EquivalentTypes(targetType, this.Type))
@ -481,7 +482,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -481,7 +482,6 @@ namespace ICSharpCode.Decompiler.CSharp
// Convert from integer/pointer to reference.
// First, convert to the corresponding pointer type:
var arg = this.ConvertTo(new PointerType(elementType), expressionBuilder, checkForOverflow);
Expression expr;
ResolveResult elementRR;
if (arg.Expression is UnaryOperatorExpression unary && unary.Operator == UnaryOperatorType.AddressOf)
{
@ -561,7 +561,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -561,7 +561,11 @@ namespace ICSharpCode.Decompiler.CSharp
return this;
}
}
var castExpr = new CastExpression(expressionBuilder.ConvertType(targetType), Expression);
// BaseReferenceExpression must not be used with CastExpressions
expr = Expression is BaseReferenceExpression
? new ThisReferenceExpression().WithILInstruction(this.ILInstructions)
: Expression;
var castExpr = new CastExpression(expressionBuilder.ConvertType(targetType), expr);
bool needsCheckAnnotation = targetUType.GetStackType().IsIntegerType();
if (needsCheckAnnotation)
{

Loading…
Cancel
Save