From 36664536838c6d83f4a2830f435109e9e747ac86 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 9 Jan 2022 12:27:02 +0100 Subject: [PATCH] fix #2605 --- TestSuite/implicitexplicit24.pas | 19 ++++++++++++++++ TestSuite/implicitexplicit25.pas | 22 +++++++++++++++++++ .../convertion_data_and_alghoritms.cs | 9 +++++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 TestSuite/implicitexplicit24.pas create mode 100644 TestSuite/implicitexplicit25.pas diff --git a/TestSuite/implicitexplicit24.pas b/TestSuite/implicitexplicit24.pas new file mode 100644 index 000000000..69f1455f3 --- /dev/null +++ b/TestSuite/implicitexplicit24.pas @@ -0,0 +1,19 @@ +var i: integer; +type + t1 = class + + static function operator implicit(o: T): t1; + begin + i := 1; + Result := nil; + end; + + end; + +function f0: t1 := nil; +procedure p0(o: t1) := exit; + +begin + var o: t1 := f0; + assert(i = 0); +end. \ No newline at end of file diff --git a/TestSuite/implicitexplicit25.pas b/TestSuite/implicitexplicit25.pas new file mode 100644 index 000000000..6492cd2f0 --- /dev/null +++ b/TestSuite/implicitexplicit25.pas @@ -0,0 +1,22 @@ +var i: integer; +type + t1 = class + + // Обязательно шаблонный operator implicit + static function operator implicit(o: T): t1; + begin + i := 1; + Result := nil; + end; + + end; + +function f0: t1 := nil; +procedure p0(o: t1) := exit; + +begin + // Обязательно вызвать f0 без скобок + // Если поставить скобки - не воспроизводится + p0(f0); + assert(i = 0); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs index 7d5a23ea3..4953af3fc 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -658,6 +658,11 @@ namespace PascalABCCompiler.TreeConverter if (pct.second!=null) { + if (pct.second.to == null && en is typed_expression && !to.IsDelegate) + { + syntax_tree_visitor.try_convert_typed_expression_to_function_call(ref en); + return en; + } AddError(new TwoTypeConversionsPossible(en,pct.first,pct.second)); } @@ -1831,7 +1836,7 @@ namespace PascalABCCompiler.TreeConverter { if (ptc.second!=null) { - if (ptc.first.from is null_type_node || ptc.second.from is null_type_node || ptc.second.from.is_generic_parameter) + if (ptc.first.from is null_type_node || ptc.second.to == null || ptc.second.from is null_type_node || ptc.second.from.is_generic_parameter) continue; // SSM 9/12/20 fix 2363 AddError(new PossibleTwoTypeConversionsInFunctionCall(loc,ptc.first,ptc.second)); } @@ -1888,6 +1893,8 @@ namespace PascalABCCompiler.TreeConverter { continue; } + if (ptcal[i].second != null && ptcal[i].second.to == null) + continue; expression_node[] temp_arr = new expression_node[1]; temp_arr[0] = exprs[i]; if (ptcal[i].first.convertion_method is compiled_constructor_node)