This commit is contained in:
Ivan Bondarev 2025-04-06 11:35:09 +02:00
parent af7abc770b
commit 28a1a03e8d
2 changed files with 26 additions and 2 deletions

14
TestSuite/lambdas27.pas Normal file
View file

@ -0,0 +1,14 @@
var i: integer;
procedure p1(o: real; d: char->());
begin
Inc(i);
end;
procedure p1(o: byte; d: ()->word) := exit;
begin
p1(0, procedure(x) ->x.ToString());
p1(0, x -> x.ToString());
assert(i = 2);
end.

View file

@ -2477,7 +2477,7 @@ namespace PascalABCCompiler.TreeConverter
}
possible_type_convertions_list_list tcll = new possible_type_convertions_list_list();
Dictionary<function_node, possible_type_convertions_list> last_chance_list = new Dictionary<function_node, possible_type_convertions_list>();
for (int i = 0; i < set_of_possible_functions.Count; i++)
{
Errors.Error err = null;
@ -2495,6 +2495,7 @@ namespace PascalABCCompiler.TreeConverter
if (fact.type is delegated_methods dm)
{
var fact_is_function_with_return_value = dm.proper_methods.Count > 0 && dm.proper_methods[0].function.return_value_type != null;
var fact_is_lambda = syntax_nodes_parameters != null && k < syntax_nodes_parameters.Count && syntax_nodes_parameters[k] is SyntaxTree.function_lambda_definition;
var form_is_procedure = false;
var form_is_delegate = false;
@ -2516,6 +2517,8 @@ namespace PascalABCCompiler.TreeConverter
if (fact_is_function_with_return_value && form_is_procedure)
{
proc_func_or_lambdaAndNotDelegate_OK_flag = false;
if (dm.proper_methods[0].function.return_value_type is lambda_any_type_node)
last_chance_list[set_of_possible_functions[i]] = tc;
break;
}
if (fact_is_lambda && !form_is_delegate) // лямбда вместо не делегата - исключает функцию из рассмотрения
@ -2579,6 +2582,12 @@ namespace PascalABCCompiler.TreeConverter
}
}
if (set_of_possible_functions.Count == 0 && indefinits.Count == 0 && last_chance_list.Count == 1)
{
tcll.AddElement(last_chance_list.First().Value);
set_of_possible_functions.Add(last_chance_list.First().Key);
}
if (set_of_possible_functions.Count == 0 && indefinits.Count == 0)
{
if (_is_assigment && parameters.Count == 2)
@ -2587,7 +2596,8 @@ namespace PascalABCCompiler.TreeConverter
err_out = new OperatorCanNotBeAppliedToThisTypes(_tmp_bfn.name, parameters[0], parameters[1], loc);
else if (is_op)
err_out = new OperatorCanNotBeAppliedToThisTypes(first_function.name, parameters[0], parameters.Count > 1 ? parameters[1] : null, loc);
else err_out = new NoFunctionWithSameArguments(FunctionName, loc, is_alone_method_defined);
else
err_out = new NoFunctionWithSameArguments(FunctionName, loc, is_alone_method_defined);
return set_of_possible_functions;
}