From e3febac2b86cd6c90227fc514e8a30f15506b5c5 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: Tue, 22 Sep 2020 21:52:03 +0200 Subject: [PATCH] fix #2310 --- TestSuite/lambda_capture_compiled_props.pas | 23 +++++++++++++++++++ .../Closure/CapturedVariablesTreeBuilder.cs | 8 ++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 TestSuite/lambda_capture_compiled_props.pas diff --git a/TestSuite/lambda_capture_compiled_props.pas b/TestSuite/lambda_capture_compiled_props.pas new file mode 100644 index 000000000..4adfe49a6 --- /dev/null +++ b/TestSuite/lambda_capture_compiled_props.pas @@ -0,0 +1,23 @@ +{$reference PresentationFramework.dll} +{$apptype windows} +var i: integer; + +type + t1 = class(System.Windows.Window) + + procedure p1; + begin + var p := procedure-> + begin + Dispatcher.Invoke(()->begin Inc(i) end); + end; + p; + end; + + end; + +begin + var o := new t1; + o.p1; + assert(i = 1); +end. \ No newline at end of file diff --git a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs index b5050b997..58ce23691 100644 --- a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs +++ b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs @@ -226,14 +226,16 @@ namespace TreeConverter.LambdaExpressions.Closure var acceptableVarType = si.sym_info.semantic_node_type == semantic_node_type.local_variable || si.sym_info.semantic_node_type == semantic_node_type.local_block_variable || si.sym_info.semantic_node_type == semantic_node_type.common_parameter || - si.sym_info.semantic_node_type == semantic_node_type.class_field + si.sym_info.semantic_node_type == semantic_node_type.class_field || + si.sym_info.semantic_node_type == semantic_node_type.basic_property_node ; //trjuk, chtoby ne perelopachivat ves kod. zamenjaem ident na self.ident // Использую этот трюк для нестатических полей предков - они не захватываются из-за плохого алгоритма захвата // 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) + || si.sym_info.semantic_node_type == semantic_node_type.common_event || si.sym_info.semantic_node_type == semantic_node_type.common_property_node + || si.sym_info.semantic_node_type == semantic_node_type.basic_property_node) && InLambdaContext) { dot_node dn = null; // Поменял принцип добавления имени класса для статических полей и функций @@ -325,7 +327,7 @@ namespace TreeConverter.LambdaExpressions.Closure } - if (!(acceptableVarType) && InLambdaContext) + if (!acceptableVarType && InLambdaContext) { _visitor.AddError(new ThisTypeOfVariablesCannotBeCaptured(_visitor.get_location(id))); return;