fix #818
This commit is contained in:
Бондарев Иван 2018-08-10 10:58:29 +02:00
parent 012409f1e4
commit 7d744570ec
3 changed files with 72 additions and 2 deletions

View file

@ -0,0 +1,31 @@
var i: integer;
procedure test;
begin
i := 1;
end;
type
t1 = class
public event Elap: procedure;
procedure p1(b:byte);
begin
var p: procedure := ()->
begin
b := 0;
if Elap <> nil then
Elap()
end;
p;
end;
end;
begin
var o := new t1;
o.Elap += test;
o.p1(2);
assert(i=1);
end.

View file

@ -0,0 +1,22 @@
type
t1 = class
_p1 := 0;
property P1:integer read _p1 write _p1; virtual;
procedure pr1;
begin
var p:procedure := ()->begin
P1 := P1 + 1;
end;
p;
end;
end;
begin
var o := new t1;
o.pr1;
assert(o.P1 = 1);
end.

View file

@ -174,9 +174,26 @@ namespace TreeConverter.LambdaExpressions.Closure
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
;
//trjuk, chtoby ne perelopachivat ves kod. zamenjaem ident na self.ident
if ((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);
bool ok = true;
try
{
id.Parent.ReplaceDescendantUnsafe(id, dn);
}
catch
{
ok = false;
}
if (ok)
{
ProcessNode(id.Parent);
return;
}
}
if (!(acceptableVarType) && InLambdaContext)
{
_visitor.AddError(new ThisTypeOfVariablesCannotBeCaptured(_visitor.get_location(id)));