#2114
This commit is contained in:
Ivan Bondarev 2021-01-08 19:56:42 +01:00
parent 12b365650f
commit 92c198c0a4
4 changed files with 61 additions and 1 deletions

View file

@ -0,0 +1,22 @@
type
TBase = class end;
TErr<T> = class(TBase)
public static function operator implicit(o: T): TErr<T>;
begin
raise new System.InvalidOperationException;
end;
end;
procedure p0<T>(o: TErr<T>) := exit;
// обязательно вызывать p0 с шаблонным параметром p1
// если вызывать p0&<word> - выводит правильное сообщение об ошибке
procedure p1<T>(q: TBase) := p0&<T>(q); // это не должно компилироваться
begin
var q: TBase;
p1&<byte>(q);
end.

View file

@ -1,4 +1,4 @@
begin
begin
var h1 := HSet(1,2,3);
var h2 := HSet(1,2,3);
assert(h1=h2);
@ -6,4 +6,10 @@ begin
h2 := HSet(1,2);
assert(h1 > h2);
assert(h2 < h1);
h1 := [1,2,3];
h2 := [1,2,3];
assert(h1=h2);
h1 := HashSet&<integer>([1,2,3]);
h2 := HashSet&<integer>([1,2,3]);
assert(h1=h2);
end.

View file

@ -0,0 +1,30 @@
var i: integer;
type
TBase = class end;
TErr<T> = class(TBase)
public static function operator implicit(o: T): TErr<T>;
begin
i := 1;
end;
end;
t1 = class(TErr<byte>) end;
// обязательно шаблонная подпрограмма и использование T ниже. Иначе не воспроизводится
procedure p1<T>;
begin
var a: TBase := new t1;
var b := TErr&<T>( a ); // тут вместо приведения типа вызывает operator implicit, который тут ну никак не подходит
// если удалить operator implicit - на этой строчке оказывается обычное приведение типа, как и должно
i := 2;
end;
begin
p1&<byte>;
assert(i = 2);
end.

View file

@ -2387,6 +2387,8 @@ namespace PascalABCCompiler.TreeRealization
continue;
}
}
else if (fn.parameters[0].type.is_generic_parameter)
continue;
return fn;
}
}