From 42f71b56f6fae19af6fb6e374dc9896adb3a621c Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 4 Dec 2019 23:13:53 +0100 Subject: [PATCH] Fix #1811: Assert in NullCoalescingInstruction.CheckInvariant after expression tree transform --- .../TestCases/Pretty/ExpressionTrees.cs | 8 +++++++- .../IL/Transforms/TransformExpressionTrees.cs | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs index 0704d886b..eb8d29d05 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs @@ -1038,7 +1038,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { await Task.Delay(100); if (string.IsNullOrEmpty(str)) { -#if ROSLYN +#if CS70 if (int.TryParse(str, out int id)) { #else int id; @@ -1050,6 +1050,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } } + + public void NullCoalescing() + { + Test>((string a, string b) => a ?? b, (string a, string b) => a ?? b); + Test>((int? a) => a ?? 1, (int? a) => a ?? 1); + } } internal static class Extensions diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs index 537c1fb03..3c93013a2 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs @@ -604,7 +604,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms } else { 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)