Browse Source

Ignore nullability annotations when comparing types in the case of implicit conversions.

pull/2642/head
Siegfried Pammer 3 years ago
parent
commit
2de6e1fe30
  1. 5
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

5
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -193,7 +193,7 @@ namespace ICSharpCode.Decompiler.CSharp
public TranslatedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder, bool checkForOverflow = false, bool allowImplicitConversion = false) public TranslatedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder, bool checkForOverflow = false, bool allowImplicitConversion = false)
{ {
var type = this.Type; var type = this.Type;
if (type.Equals(targetType)) if (NormalizeTypeVisitor.IgnoreNullabilityAndTuples.EquivalentTypes(type, targetType))
{ {
// Make explicit conversion implicit, if possible // Make explicit conversion implicit, if possible
if (allowImplicitConversion) if (allowImplicitConversion)
@ -225,7 +225,8 @@ namespace ICSharpCode.Decompiler.CSharp
} }
case InvocationResolveResult invocation: case InvocationResolveResult invocation:
{ {
if (Expression is ObjectCreateExpression oce && oce.Arguments.Count == 1 && invocation.Type.IsKnownType(KnownTypeCode.NullableOfT)) if (Expression is ObjectCreateExpression oce && oce.Arguments.Count == 1
&& invocation.Type.IsKnownType(KnownTypeCode.NullableOfT))
{ {
return this.UnwrapChild(oce.Arguments.Single()); return this.UnwrapChild(oce.Arguments.Single());
} }

Loading…
Cancel
Save