From b2ac415b2c888919951f817e064cfcb15b8355c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 15 Oct 2017 19:29:50 +0200 Subject: [PATCH] bug fix #496 --- TestSuite/lambdas_closures_12.pas | 24 +++++++++++++++++++ .../TreeConversion/compilation_context.cs | 11 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 TestSuite/lambdas_closures_12.pas diff --git a/TestSuite/lambdas_closures_12.pas b/TestSuite/lambdas_closures_12.pas new file mode 100644 index 000000000..654d0caed --- /dev/null +++ b/TestSuite/lambdas_closures_12.pas @@ -0,0 +1,24 @@ +var i: integer; +type + t2 = class + procedure Redraw; + begin + i := 1; + end; + + constructor(Redraw: boolean); + begin + var p:procedure := ()-> + begin + if Redraw then + self.Redraw; + end; + p; + end; + + end; + +begin +new t2(true); +assert(i = 1); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/compilation_context.cs b/TreeConverter/TreeConversion/compilation_context.cs index 8f492a17e..bb7c7798d 100644 --- a/TreeConverter/TreeConversion/compilation_context.cs +++ b/TreeConverter/TreeConversion/compilation_context.cs @@ -2130,7 +2130,16 @@ namespace PascalABCCompiler.TreeConverter SymbolInfoList si = curscope.Find(name, curscope); - + SymbolInfoList si2 = null; + if (si != null && si.First().scope is SymbolTable.ClassScope && curscope.TopScope is SymbolTable.BlockScope && curscope.TopScope.TopScope is SymbolTable.ClassMethodScope && curscope.TopScope.TopScope.TopScope is SymbolTable.BlockScope) + { + si2 = curscope.TopScope.TopScope.TopScope.Find(name, curscope.TopScope.TopScope.TopScope); + if (si2 != null && si2.First().scope is SymbolTable.ClassMethodScope) + { + si = si2; + } + } + if (si == null && _compiled_tn != null && curscope.TopScope != null) { SymbolTable.Scope tmp = curscope.TopScope;