Browse Source

Disable ref inline assignments.

This increases the chances that we'll avoid CS8174: A declaration of a by-reference variable must have an initializer.
pull/1213/head
Daniel Grunwald 7 years ago
parent
commit
4580eab7ab
  1. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  2. 8
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -4553,6 +4553,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -4553,6 +4553,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if !LEGACY_CSC
// Legacy csc generates a slightly different pattern for string compound assignment
// as for all other compound assignments. We'll ignore that edge case.
// Note: it's possible that the pre-CopyPropagation run of TransformAssignments is causing trouble there,
// and that the compound assignment transform would be fine if it didn't get disrupted.
private static void Issue1082(string[] strings, List<char> chars, bool flag, int i)
{

8
ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

@ -350,6 +350,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -350,6 +350,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// 'stloc l' is implicitly truncating the stack value
return false;
}
if (nextInst.Variable.StackType == StackType.Ref) {
// ref locals need to be initialized when they are declared, so
// we can only use inline assignments when we know that the
// ref local is definitely assigned.
// We don't have an easy way to check for that in this transform,
// so avoid inline assignments to ref locals for now.
return false;
}
context.Step("Inline assignment to local variable", inst);
var value = inst.Value;
var var = nextInst.Variable;

Loading…
Cancel
Save