Sign in Join

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

Mailing lists / fpc-pascal / 2021-03

Extraneous generic parameters

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Ryan Joseph

This program compiles, but is it a bug? I would think the specialization should fail because "S" in TArray is not specified.

========================

{$mode objfpc}
type
  generic TArray<T, S> = array of T;
generic procedure DoThis<T>(param: specialize TArray<specialize TArray<T>>);
begin
end;
begin
  specialize DoThis<integer>([[1],[2],[3]]);
end.

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Ryan Joseph
Ryan Joseph wrote 16 lines
This program compiles, but is it a bug? I would think the specialization should fail because "S" in TArray is not specified. ======================== {$mode objfpc} type generic TArray<T, S> = array of T; generic procedure DoThis<T>(param: specialize TArray<specialize TArray<T>>); begin end; begin specialize DoThis<integer>([[1],[2],[3]]); end.

The TArray<T> generic type is part of the ObjPas unit, so the compiler simply picks that instead of that of your program. ;)

Regards,
Sven

Reply by email

Ryan Joseph
to Sven Barth
On Mar 15, 2021, at 12:42 AM, Sven Barth wrote: The TArray<T> generic type is part of the ObjPas unit, so the compiler simply picks that instead of that of your program. ;)

Sneaky but that explains the issue.

Btw since we're on the topic of arrays. Are short strings and static arrays not able to be generics? I tried that and got parser errors.

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Ryan Joseph

Ryan Joseph via fpc-pascal schrieb am
Mo., 15. März 2021, 20:45:

Show quoted text 10 lines
> On Mar 15, 2021, at 12:42 AM, Sven Barth wrote: > > The TArray<T> generic type is part of the ObjPas unit, so the compiler simply picks that instead of that of your program. ;) Sneaky but that explains the issue.

It's part of the generic type overloading inherited from Delphi. *shrugs*

Btw since we're on the topic of arrays. Are short strings and static arrays not able to be generics? I tried that and got parser errors.

That is correct. File, set or pointers are not supported either for example.

Regards,
Sven

Reply by email