diff --git a/TestSuite/lambda_closure_class_fields_7.pas b/TestSuite/lambda_closure_class_fields_7.pas new file mode 100644 index 000000000..a395b8bb8 --- /dev/null +++ b/TestSuite/lambda_closure_class_fields_7.pas @@ -0,0 +1,21 @@ +type + t0 = class + public static a1: byte := 2; + + public static function f1: integer; + begin + Result := 1 + end; + end; + t1 = class(t0) + private procedure p1; + begin + var a2: word := 3; + var pp1: ()->integer := ()->a1+a2+f1; + Assert(pp1=6); + end; + end; + +begin + t1.Create.p1 +end. \ No newline at end of file diff --git a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs index 220fcd526..1e0b964ef 100644 --- a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs +++ b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs @@ -189,11 +189,22 @@ namespace TreeConverter.LambdaExpressions.Closure ; //trjuk, chtoby ne perelopachivat ves kod. zamenjaem ident na self.ident // Использую этот трюк для нестатических полей предков - они не захватываются из-за плохого алгоритма захвата - if ((si.sym_info.semantic_node_type == semantic_node_type.class_field && !(si.sym_info as class_field).IsStatic - || si.sym_info.semantic_node_type == semantic_node_type.common_method_node && !(si.sym_info as common_method_node).IsStatic + // aab 12.06.19 begin + // Добавил такое же переименование для статичесских полей класса. Теперь захват работает + if ((si.sym_info.semantic_node_type == semantic_node_type.class_field || si.sym_info.semantic_node_type == semantic_node_type.common_method_node || si.sym_info.semantic_node_type == semantic_node_type.common_event || si.sym_info.semantic_node_type == semantic_node_type.common_property_node) && InLambdaContext) { - dot_node dn = new dot_node(new ident("self", id.source_context), new ident(id.name, id.source_context), id.source_context); + dot_node dn = null; + if (si.sym_info.semantic_node_type == semantic_node_type.class_field && (si.sym_info as class_field).IsStatic + || si.sym_info.semantic_node_type == semantic_node_type.common_method_node && (si.sym_info as common_method_node).IsStatic) + { + dn = new dot_node(new ident(si.scope.Name.Remove(0, 6), id.source_context), new ident(id.name, id.source_context), id.source_context); + } + else + { + dn = new dot_node(new ident("self", id.source_context), new ident(id.name, id.source_context), id.source_context); + } + // aab 12.06.19 end bool ok = true; try {