Browse Source

Fix #2143: Missing `this.` qualification in lambda

pull/2145/head
Siegfried Pammer 5 years ago
parent
commit
549f7fb44d
  1. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs
  2. 27
      ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs

7
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs

@ -32,6 +32,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -32,6 +32,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public string Value;
}
private int x;
public Action CaptureOfThis()
{
return delegate {
@ -134,6 +136,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -134,6 +136,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
});
}
public Func<int, int> Issue2143()
{
return (int x) => this.x;
}
public Action<object> Bug971_DelegateWithoutParameterList()
{
return delegate {

27
ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs

@ -104,11 +104,7 @@ namespace ICSharpCode.Decompiler.IL @@ -104,11 +104,7 @@ namespace ICSharpCode.Decompiler.IL
{
for (int i = 0; i < list.Count;)
{
var v = list[i];
// Note: we cannot remove display-class locals from the collection,
// even if they are unused - which is always the case, if TDCU succeeds,
// because they are necessary for PDB generation to produce correct results.
if (v.IsDead && v.Kind != VariableKind.DisplayClassLocal)
if (ShouldRemoveVariable(list[i]))
{
RemoveAt(i);
}
@ -117,6 +113,27 @@ namespace ICSharpCode.Decompiler.IL @@ -117,6 +113,27 @@ namespace ICSharpCode.Decompiler.IL
i++;
}
}
static bool ShouldRemoveVariable(ILVariable v)
{
if (!v.IsDead)
return false;
// Note: we cannot remove display-class locals from the collection,
// even if they are unused - which is always the case, if TDCU succeeds,
// because they are necessary for PDB generation to produce correct results.
if (v.Kind == VariableKind.DisplayClassLocal)
return false;
// Do not remove parameter variables, as these are defined even if unused.
if (v.Kind == VariableKind.Parameter)
{
// However, remove unused this-parameters of delegates, expression trees, etc.
// These will be replaced with the top-level function's this-parameter.
if (v.Index == -1 && v.Function.Kind != ILFunctionKind.TopLevelFunction)
return true;
return false;
}
return true;
}
}
public int Count {

Loading…
Cancel
Save