Sign in Join

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

Mailing lists / fpc-pascal / 2018-11

Restricted generic param types

2 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

I’m getting a parse error here. It thinks the “U” is another type but in fact it’s another generic parameter and not related to this a bug? I don’t think the way the parsing works the compiler actually can discern this condition.

{$mode objfpc}
{$modeswitch advancedrecords}
program generic_constants_restricted;
type
	generic TList<T:tobject, U> = record
	end;
begin
end.

Regards,
Ryan Joseph

Sven Barth
to Ryan Joseph

Am Fr., 9. Nov. 2018, 05:48 hat Ryan Joseph
geschrieben:

Show quoted text 17 lines
I’m getting a parse error here. It thinks the “U” is another type but in fact it’s another generic parameter and not related to this a bug? I don’t think the way the parsing works the compiler actually can discern this condition. {$mode objfpc} {$modeswitch advancedrecords} program generic_constants_restricted; type generic TList<T:tobject, U> = record end; begin end.

You must use ";" in that case. All parameters separated by "," are of the same "constraint type" while ";" separates these. Essentially like a parameter declaration for a function.
(and yes, Delphi handles it like that as well)

Regards,
Sven