Browse Source

Fix #1811: Assert in NullCoalescingInstruction.CheckInvariant after expression tree transform

pull/1843/head
Daniel Grunwald 6 years ago
parent
commit
42f71b56f6
  1. 8
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs
  2. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

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

@ -1038,7 +1038,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
await Task.Delay(100); await Task.Delay(100);
if (string.IsNullOrEmpty(str)) { if (string.IsNullOrEmpty(str)) {
#if ROSLYN #if CS70
if (int.TryParse(str, out int id)) { if (int.TryParse(str, out int id)) {
#else #else
int id; int id;
@ -1050,6 +1050,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
} }
} }
public void NullCoalescing()
{
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);
}
} }
internal static class Extensions internal static class Extensions

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

@ -604,7 +604,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} else { } else {
targetType = fallbackInstType; targetType = fallbackInstType;
} }
return (new NullCoalescingInstruction(kind, trueInst, fallbackInst), targetType); return (new NullCoalescingInstruction(kind, trueInst, fallbackInst) {
UnderlyingResultType = trueInstTypeNonNullable.GetStackType()
}, targetType);
} }
(ILInstruction, IType) ConvertComparison(CallInstruction invocation, ComparisonKind kind) (ILInstruction, IType) ConvertComparison(CallInstruction invocation, ComparisonKind kind)

Loading…
Cancel
Save