Browse Source

Fix NRE with tuple discards in DeconstructionTransform

pull/2119/head
Siegfried Pammer 5 years ago
parent
commit
9eb0a98854
  1. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs
  2. 11
      ICSharpCode.Decompiler/IL/Transforms/DeconstructionTransform.cs

5
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs

@ -216,5 +216,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -216,5 +216,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
(Get(0).NMy, Get(1).My) = GetTuple<MyInt?, MyInt>();
}
public void Tuple_Property_NoConversion_DiscardLast()
{
(Get(0).NMy, Get(1).My, _) = GetTuple<MyInt?, MyInt, int>();
}
}
}

11
ICSharpCode.Decompiler/IL/Transforms/DeconstructionTransform.cs

@ -209,8 +209,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -209,8 +209,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms
IsDeconstructTuple = this.tupleType != null
};
int index = 0;
foreach (ILVariable result in deconstructionResults) {
result.Kind = VariableKind.PatternLocal;
foreach (ILVariable v in deconstructionResults) {
var result = v;
if (result == null) {
var freshVar = new ILVariable(VariableKind.PatternLocal, this.tupleType.ElementTypes[index]) { Name = "E_" + index };
context.Function.Variables.Add(freshVar);
result = freshVar;
} else {
result.Kind = VariableKind.PatternLocal;
}
replacement.Pattern.SubPatterns.Add(
new MatchInstruction(
result,

Loading…
Cancel
Save