From 27dafcbdfd5a62def96be906f935e77d60647c3d Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 4 Apr 2021 11:04:27 +0200 Subject: [PATCH] #2467 --- TestSuite/with3.pas | 24 +++++++++++++++++++ .../TreeConversion/syntax_tree_visitor.cs | 5 ++++ 2 files changed, 29 insertions(+) create mode 100644 TestSuite/with3.pas diff --git a/TestSuite/with3.pas b/TestSuite/with3.pas new file mode 100644 index 000000000..ca3ca0c46 --- /dev/null +++ b/TestSuite/with3.pas @@ -0,0 +1,24 @@ +type + node = class + i: integer; + function f1: node := new node; + end; + +begin + var n1 := new node; + var n2: node; + with n1 do + begin + // Обязательно вложенный with + n2 := f1; + with n2 do + begin + i := 2; + end; + // Обязательно вызвать метод после вложенного with + f1; + i := 1; + end; + assert(n1.i = 1); + assert(n2.i = 2); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 85bd6d3e4..4ec2b6d42 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -9022,6 +9022,11 @@ namespace PascalABCCompiler.TreeConverter foreach (expression_node vr in VarRefs) { context.WithVariables.Remove(vr.type.Scope); + if (!context.WithVariables.ContainsKey(vr.type.Scope) && OldWithVariables.ContainsKey(vr.type.Scope)) + { + context.WithVariables.Add(vr.type.Scope, OldWithVariables[vr.type.Scope]); + OldWithVariables.Remove(vr.type.Scope); + } type_node tn = vr.type.base_type; while (tn != null) {