在我修复的某些代码中,大量使用了泛型和接口类型,我遇到了错误E2134,“Type '' has no type info.”。我认为这是因为我正在进行重构,一些深度嵌套的单元集都使用了泛型,但错误并没有发生在我可以利用错误消息修复代码的位置,因为出现错误的位置代码没有问题。
以下是上下文(模拟),因为我无法发布太多代码:
上述的“const Param”没有类型信息。在我看来,这是Pascal/Delphi的一个奇怪之处,完全违反了Wirth强类型的思想。它的类型弱到像C语言中的“void *”指针或Delphi中的“Pointer”类型,但它很少使用,除了像Move等标准的Pre-Object-Pascal RTL函数中。在我的观点中,在泛型中使用的接口中的无类型参数应该被允许或禁止,而不是有时允许,有时禁止。
这是1978年Pascal特性与2009年ObjectPascal特性混合的一个案例。
以下是上下文(模拟),因为我无法发布太多代码:
unit GenericThing;
...
interface
...
type
...
IThingListOf<ThingT> = interface( IThingContainer )
function getEnumerator: TEnumerator<ThingT>;
function getCount: Integer;
function getThing( Index: integer ): ThingT;
function getFirst: ThingT;
function IndexOf( value: ThingT): integer;
function addItem( const Thing: ThingT ): ThingT;
function removeItem( const Thing: ThingT ): Integer;
procedure clear;
procedure Sort; overload;
procedure Sort(const AComparer: IComparer<ThingT>); overload;
property Count: integer read getCount;
property First: ThingT read getFirst;
property Items[Index: integer]: ThingT read getThing; default;
end;
// error appears on whatever line number comes after the declaration of IThingListOf<ThingT>...end;
function AnythingYouLikeHere:Integer; // there is nothign wrong with this line, but you get the E2134 here.
看起来问题在于IThingContainer本身:
IThingContainer = interface ...
...
procedure DoSomething(const Param);
end;
上述的“const Param”没有类型信息。在我看来,这是Pascal/Delphi的一个奇怪之处,完全违反了Wirth强类型的思想。它的类型弱到像C语言中的“void *”指针或Delphi中的“Pointer”类型,但它很少使用,除了像Move等标准的Pre-Object-Pascal RTL函数中。在我的观点中,在泛型中使用的接口中的无类型参数应该被允许或禁止,而不是有时允许,有时禁止。
这是1978年Pascal特性与2009年ObjectPascal特性混合的一个案例。