This commit is contained in:
Бондарев Иван 2017-08-10 15:53:37 +02:00
parent dccde94e62
commit 10686d94e8
2 changed files with 28 additions and 0 deletions

15
TestSuite/lambdas3.pas Normal file
View file

@ -0,0 +1,15 @@
var i: integer;
procedure test;
begin
Inc(i);
end;
procedure Cycle(p: procedure);
begin
10.Times.ForEach(x->p()); // Âñ¸ îñòàëüíîå ðàáîòàåò
end;
begin
Cycle(test);
assert(i=10);
end.

View file

@ -18544,10 +18544,14 @@ namespace PascalABCCompiler.TreeConverter
// Надо посмотреть, как это делается для преобразования типов T(x). А пока так
expression_node qq = null;
delegated_methods dm = null;
common_type_node delegate_type = null;
try
{
qq = convert_strong(ff.dereferencing_value);
dm = qq.type as delegated_methods;
if (dm == null && qq.type.IsDelegate)
delegate_type = qq.type as common_type_node;
}
catch (Exception e)
{
@ -18564,6 +18568,15 @@ namespace PascalABCCompiler.TreeConverter
_function_lambda_definition.return_type = null;
}
}
else if (delegate_type != null)
{
function_node fn = delegate_type.find_in_type("Invoke").InfoUnitList[0].sym_info as function_node;
if (fn.return_value_type == null && stl.expr_lambda_body)
{
stl.list[0] = new procedure_call(ff, ff.source_context);
_function_lambda_definition.return_type = null;
}
}
}
}
else // значит, первый и единственный оператор - не присваивание и это лямбда - процедура!