fix #1968
This commit is contained in:
parent
76f4020256
commit
46b5f21452
21
TestSuite/lambda_closure_class_fields_7.pas
Normal file
21
TestSuite/lambda_closure_class_fields_7.pas
Normal file
|
|
@ -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.
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue