Testing a possible generics related compiler error. UPDATE: It's a feature, not a bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program GenericsIssue; | |
{$APPTYPE CONSOLE} | |
{$R *.res} | |
//Simplified test case for https://quality.embarcadero.com/browse/RSP-32427 | |
uses | |
System.SysUtils, System.Rtti; | |
type | |
TFoo = class(TObject) | |
public | |
function DoSomething(SomeObject: TValue): string; overload; | |
function DoSomething<T>(SomeObject: T): string; overload; | |
end; | |
TBar = class(TObject) | |
end; | |
{ TFoo } | |
function TFoo.DoSomething(SomeObject: TValue): string; | |
begin | |
result := 'NON GENERIC'; | |
end; | |
function TFoo.DoSomething<T>(SomeObject: T): string; | |
begin | |
result := 'GENERIC'; | |
end; | |
begin | |
var | |
Foo := TFoo.Create; | |
var | |
Bar := TBar.Create; | |
try | |
//Both variants of calling "DoSomething" will be resolved to the generic method. | |
//This is because type parameters can be omitted, in which case the type is infered. | |
//As type inferrence takes precedence over overload resolution, the generic implementation get's called in both cases. | |
Assert(Foo.DoSomething(Bar) = 'GENERIC', 'Non Generic Call'); | |
Assert(Foo.DoSomething<TBar>(Bar) = 'GENERIC', 'Generic Call'); | |
except | |
on E: Exception do | |
Writeln(E.ClassName, ': ', E.Message); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment