I have the following declaration of a class in Delphi XE8:
TestClass = class;
TestClass = class
function test<T: TestClass>(supplier: TFunc<T>): T; // Compiler error
end;
Which throws the following compiler error:
E2086 Type 'TestClass' is not yet completely defined
When I add another class to the mix and use that one as constraint instead, it works fine:
AnotherTestClass = class
end;
TestClass = class;
TestClass = class
function test<T: AnotherTestClass>(supplier: TFunc<T>): T; // No Error
end;
I suspect the problem is that the forward type declaration does not tell Delphi enough about the TestClass
type yet. This is perhaps more obvious since the following attempt to work around the problem throws the very same compiler error on a different line:
TestClass = class;
AnotherTestClass = class (TestClass) // Compiler Error
end;
TestClass = class
function test<T: AnotherTestClass>(supplier: TFunc<T>): T;
end;
Am I doing something wrong and if not, is there a way around this problem?