[fpc-pascal] Constants in generics
pascaldragon at googlemail.com
Thu Jan 3 14:20:47 CET 2019
Am Do., 3. Jan. 2019, 12:58 hat Alexander Shishkin via fpc-pascal <
fpc-pascal at lists.freepascal.org> geschrieben:
> 03.01.2019 6:32, Ryan Joseph пишет:
> >> On Jan 2, 2019, at 8:25 PM, Alexander Shishkin via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >> This is not consistent with constraints. Should be ";" after T.
> >> And what about following examples?
> > The semicolon is only needed following a generic parameter which is
> constrained. This was the normal behavior before constants were introduced.
> > generic TMyRecord1<T: TObject; const U: integer> = record
> It is not exactly true, semicolon separates parameter lists different
> restrictions including empty one.
> This should fail to compile (": integer" restriction can not be applied
> to non const parameter):
> generic TMyRecord1<T, const U: integer> = record end;
> generic TMyRecord1<const T, U: integer> = record end;
> This is OK (T is any type):
> generic TMyRecord1<T; const U: integer> = record end;
> This is OK (both T and U are integer):
> generic TMyRecord1<const T, const U: integer> = record end;
> This is OK (T is any const, U and V are integer)
> generic TMyRecord1<const T; const U, const V: integer> = record end;
Correct. ";" separates different parameter types, "," separates those of
the same type. Though I agree with Mattias that "const T, const U" (with or
without ": Integer") should not work (but then "T, const U" should also not
work for consistency).
Essentially it should behave like a routine's parameter clause.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal