Browse Source

Merge pull request #2289 from wwh1004/fix4

Fix wrong nullable lift
pull/2308/head
Siegfried Pammer 4 years ago committed by GitHub
parent
commit
501d418f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs
  2. 23
      ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs

@ -894,6 +894,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -894,6 +894,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Test<Func<string, string, string>>((string a, string b) => a ?? b, (string a, string b) => a ?? b);
Test<Func<int?, int>>((int? a) => a ?? 1, (int? a) => a ?? 1);
}
public void NullableLifting(Guid? a, Guid? b)
{
ToCode(null, () => a == b);
ToCode(null, () => (Guid)a == (Guid)b);
}
}
internal static class Extensions

23
ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

@ -515,15 +515,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -515,15 +515,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Arguments = { left(), right() }
}, method.ReturnType);
case 4:
if (!invocation.Arguments[2].MatchLdcI4(out var isLifted))
if (!invocation.Arguments[2].MatchLdcI4(out var isLiftedToNull))
return (null, SpecialType.UnknownType);
if (!MatchGetMethodFromHandle(invocation.Arguments[3], out method))
return (null, SpecialType.UnknownType);
if (isLifted != 0)
bool isLifted = NullableType.IsNullable(leftType);
if (isLifted)
method = CSharpOperators.LiftUserDefinedOperator((IMethod)method);
return (() => new Call((IMethod)method) {
Arguments = { left(), right() }
}, method.ReturnType);
}, isLiftedToNull != 0 ? NullableType.Create(method.Compilation, method.ReturnType) : method.ReturnType);
default:
return (null, SpecialType.UnknownType);
}
@ -729,13 +730,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -729,13 +730,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var (right, rightType) = ConvertInstruction(invocation.Arguments[1]);
if (right == null)
return (null, SpecialType.UnknownType);
if (invocation.Arguments.Count == 4 && invocation.Arguments[2].MatchLdcI4(out var isLifted) && MatchGetMethodFromHandle(invocation.Arguments[3], out var method))
if (invocation.Arguments.Count == 4 && invocation.Arguments[2].MatchLdcI4(out var isLiftedToNull) && MatchGetMethodFromHandle(invocation.Arguments[3], out var method))
{
if (isLifted != 0)
{
bool isLifted = NullableType.IsNullable(leftType);
if (isLifted)
method = CSharpOperators.LiftUserDefinedOperator((IMethod)method);
}
return (() => new Call((IMethod)method) { Arguments = { left(), right() } }, method.ReturnType);
return (() => new Call((IMethod)method) { Arguments = { left(), right() } }, isLiftedToNull != 0 ? NullableType.Create(method.Compilation, method.ReturnType) : method.ReturnType);
}
var rr = resolver.ResolveBinaryOperator(kind.ToBinaryOperatorType(), new ResolveResult(leftType), new ResolveResult(rightType)) as OperatorResolveResult;
if (rr != null && !rr.IsError && rr.UserDefinedOperatorMethod != null)
@ -979,15 +979,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -979,15 +979,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Arguments = { left(), right() }
}, method.ReturnType);
case 4:
if (!invocation.Arguments[2].MatchLdcI4(out var isLifted))
if (!invocation.Arguments[2].MatchLdcI4(out var isLiftedToNull))
return (null, SpecialType.UnknownType);
if (!MatchGetMethodFromHandle(invocation.Arguments[3], out method))
return (null, SpecialType.UnknownType);
if (isLifted != 0)
bool isLifted = NullableType.IsNullable(leftType);
if (isLifted)
method = CSharpOperators.LiftUserDefinedOperator((IMethod)method);
return (() => new Call((IMethod)method) {
Arguments = { left(), right() }
}, method.ReturnType);
}, isLiftedToNull != 0 ? NullableType.Create(method.Compilation, method.ReturnType) : method.ReturnType);
default:
return (null, SpecialType.UnknownType);
}

Loading…
Cancel
Save