From 7bbbf39e3af72a926c0cc9c439de7dffd2cc6ede Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 25 Sep 2017 17:14:06 +0200 Subject: [PATCH] Fix #867: Async delegate tries to access variables with "this." although they are local. --- .../IL/Transforms/DelegateConstruction.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 3d49bf927..10e482e7c 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -162,6 +162,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// Replaces loads of 'this' with the target expression. + /// Async delegates use: ldobj(ldloca this). /// class ReplaceDelegateTargetVisitor : ILVisitor { @@ -183,12 +184,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms protected internal override void VisitLdLoc(LdLoc inst) { - if (inst.MatchLdLoc(thisVariable)) { + if (inst.Variable == thisVariable) { inst.ReplaceWith(target.Clone()); return; } base.VisitLdLoc(inst); } + + protected internal override void VisitLdObj(LdObj inst) + { + if (inst.Target.MatchLdLoca(thisVariable)) { + inst.ReplaceWith(target.Clone()); + return; + } + base.VisitLdObj(inst); + } } ///