fix #1009
This commit is contained in:
parent
40f0e6af8c
commit
ff319e3920
31
TestSuite/lambdas_events.pas
Normal file
31
TestSuite/lambdas_events.pas
Normal 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 self.Elap <> nil then
|
||||||
|
self.Elap()
|
||||||
|
end;
|
||||||
|
p;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
var o := new t1;
|
||||||
|
o.Elap += test;
|
||||||
|
o.p1(2);
|
||||||
|
assert(i=1);
|
||||||
|
end.
|
||||||
|
|
@ -142,6 +142,17 @@ namespace PascalABCCompiler.TreeConverter
|
||||||
return id.Contains(lambdaPrefix);
|
return id.Contains(lambdaPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsCapturedSelf(expression_node ex)
|
||||||
|
{
|
||||||
|
if (ex is class_field_reference)
|
||||||
|
{
|
||||||
|
class_field fld = (ex as class_field_reference).field;
|
||||||
|
if (fld.name.Contains("<>local_variables_class"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsAuxiliaryLambdaName(ident id)
|
public static bool IsAuxiliaryLambdaName(ident id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
|
|
|
||||||
|
|
@ -9171,7 +9171,7 @@ namespace PascalABCCompiler.TreeConverter
|
||||||
private expression_node expression_value_reciving(SyntaxTree.ident id_right, List<SymbolInfo> sil, expression_node en, bool expected_delegate)
|
private expression_node expression_value_reciving(SyntaxTree.ident id_right, List<SymbolInfo> sil, expression_node en, bool expected_delegate)
|
||||||
{
|
{
|
||||||
general_node_type[] node_types;
|
general_node_type[] node_types;
|
||||||
if (en is this_node)
|
if (en is this_node || LambdaHelper.IsCapturedSelf(en))
|
||||||
node_types = new general_node_type[] { general_node_type.variable_node,
|
node_types = new general_node_type[] { general_node_type.variable_node,
|
||||||
general_node_type.function_node, general_node_type.property_node, general_node_type.constant_definition, general_node_type.event_node};
|
general_node_type.function_node, general_node_type.property_node, general_node_type.constant_definition, general_node_type.event_node};
|
||||||
else
|
else
|
||||||
|
|
@ -16472,7 +16472,7 @@ namespace PascalABCCompiler.TreeConverter
|
||||||
{
|
{
|
||||||
if ((left as static_event_reference).en is compiled_event)
|
if ((left as static_event_reference).en is compiled_event)
|
||||||
AddError(left.location, "EVENT_{0}_MUST_BE_IN_LEFT_PART", (left as static_event_reference).en.name);
|
AddError(left.location, "EVENT_{0}_MUST_BE_IN_LEFT_PART", (left as static_event_reference).en.name);
|
||||||
if (context.converted_type != null && context.converted_type != ((left as static_event_reference).en as common_event).cont_type)
|
if (context.converted_type != null && context.converted_type != ((left as static_event_reference).en as common_event).cont_type && !context.converted_type.name.Contains("<>local_variables_class"))
|
||||||
AddError(left.location, "EVENT_{0}_MUST_BE_IN_LEFT_PART", (left as static_event_reference).en.name);
|
AddError(left.location, "EVENT_{0}_MUST_BE_IN_LEFT_PART", (left as static_event_reference).en.name);
|
||||||
}
|
}
|
||||||
else if (right is static_event_reference)
|
else if (right is static_event_reference)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue