From 73de1ce6398fe43ff03e486c841ecbc05d3acfec Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Thu, 4 Jan 2024 12:06:00 +0100 Subject: [PATCH] #2677 --- TestSuite/implicitexplicit27.pas | 27 +++++++++++++++++++ .../convertion_data_and_alghoritms.cs | 8 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 TestSuite/implicitexplicit27.pas diff --git a/TestSuite/implicitexplicit27.pas b/TestSuite/implicitexplicit27.pas new file mode 100644 index 000000000..d1f61e87a --- /dev/null +++ b/TestSuite/implicitexplicit27.pas @@ -0,0 +1,27 @@ +var i: integer; +type + t1 = class + + static function operator implicit(o: T): t1; + begin + i := 1; + end; + + end; + +procedure p1; +begin + var a: t1 := new t1(); + //Ошибка: Возможны два преобразования типа: к типу t1 и к типу t1 + var b := if false then a else nil; + assert(i = 0); + b := nil; + assert(i = 0); + var v: T; + b := v; + assert(i = 1); +end; + +begin + p1&; +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 8c5f5dd4e..1d18fbe52 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -663,7 +663,13 @@ namespace PascalABCCompiler.TreeConverter syntax_tree_visitor.try_convert_typed_expression_to_function_call(ref en); return en; } - AddError(new TwoTypeConversionsPossible(en,pct.first,pct.second)); + if (en is null_const_node && pct.first.convertion_method is basic_function_node) + { + en.type = to; + return en; + } + else + AddError(new TwoTypeConversionsPossible(en,pct.first,pct.second)); } if (pct.first==null)