This commit is contained in:
Ivan Bondarev 2024-01-04 12:06:00 +01:00
parent 7e0a13c6d0
commit 73de1ce639
2 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,27 @@
var i: integer;
type
t1<T> = class
static function operator implicit(o: T): t1<T>;
begin
i := 1;
end;
end;
procedure p1<T>;
begin
var a: t1<T> := new t1<T>();
//Ошибка: Возможны два преобразования типа: к типу t1<T> и к типу t1<T>
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&<integer>;
end.

View file

@ -663,7 +663,13 @@ namespace PascalABCCompiler.TreeConverter
syntax_tree_visitor.try_convert_typed_expression_to_function_call(ref en); syntax_tree_visitor.try_convert_typed_expression_to_function_call(ref en);
return 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) if (pct.first==null)