Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-10

TypeInfo on generic templates

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

Is it possible that the TypeInfo intrinsic could work with generic template types or is this a bug? I get "Illegal qualifier" in the procedure below.

generic procedure DoThis<T>(a: array of T);
begin
  writeln(TypeInfo(T)^.name);
end;

Regards,
Ryan Joseph

Reply by email

Howard Page-Clark
to Ryan Joseph
Ryan Joseph wrote 14 lines
Is it possible that the TypeInfo intrinsic could work with generic template types or is this a bug? I get "Illegal qualifier" in the procedure below. generic procedure DoThis<T>(a: array of T); begin writeln(TypeInfo(T)^.name); end; Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

What could .name return in this context?

"placeholder for an as-yet-unspecialised and unknown type"?

Reply by email

Ryan Joseph
to Ryan Joseph: Is it possible that the TypeInfo intrinsic could work with generic template types or is…
Show quoted text 8 lines
On Oct 29, 2020, at 12:27 PM, Ryan Joseph wrote: Is it possible that the TypeInfo intrinsic could work with generic template types or is this a bug? I get "Illegal qualifier" in the procedure below. generic procedure DoThis<T>(a: array of T); begin writeln(TypeInfo(T)^.name); end;

Oops I think you're right, I was just using TypeInfo wrong (should cast to PTypeInfo). Please disregard.

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Ryan Joseph: Is it possible that the TypeInfo intrinsic could work with generic template types or is…
Ryan Joseph wrote 6 lines
Is it possible that the TypeInfo intrinsic could work with generic template types or is this a bug? I get "Illegal qualifier" in the procedure below. generic procedure DoThis<T>(a: array of T); begin writeln(TypeInfo(T)^.name); end;

This would fail with a non-generic as well, because the TypeInfo() intrinsic returns a plain Pointer. You need to cast it to PTypeInfo (and obviously the unit TypInfo needs to be used):

PTypeInfo(TypeInfo(T))^.Name

Regards,
Sven

Reply by email