[fpc-pascal] Constants in generics
Benito van der Zander
benito at benibela.de
Tue Jan 8 23:49:21 CET 2019
Hi,
that reminds me of https://bugs.freepascal.org/view.php?id=34232
Bye,
Benito
Am 08.01.19 um 23:28 schrieb Sven Barth via fpc-pascal:
> Am Di., 8. Jan. 2019, 21:01 hat Ryan Joseph
> <ryan at thealchemistguild.com <mailto:ryan at thealchemistguild.com>>
> geschrieben:
>
> I’ve made constants respect their proper definition now so we can
> do range checking but this broke some other things. For example
> there’s a range check error with static arrays now because “U” has
> a value of 0 so 0-1 = -1:
>
> type
> generic TList<const U:byte> = record
> list: array[0..U-1] of integer; // ERROR: high
> value < low value (0..-1)
> end;
>
>
> There’s a couple ways to resolve this:
>
> 1) Add some extra flags to nodes/syms so “U-1” can be known to
> contain a generic parameter and errors can be ignored. That’s the
> most complicated solution and I wasn’t able to figure that out
> easily because flags need to be transferred in multiple locations.
>
>
> This is the preferred solution as otherwise you'd also defeat the
> purpose of type safety and probably open another can of worms when
> constant parameters are used in more complex expressions.
>
> The symbols should already have sp_generic_param set (if not that
> should definitely be changed so that it matches the type symbols). Now
> you only need a way to differentiate whether the symbol is an
> undefined generic parameter or not.
> For type parameters it abuses the fact that the undefined defs of the
> parameters are children of the generic while the final types are never
> children of the generic. Maybe we can use something similar for the
> constants?
> If not we can always add some flag to tconstsym...
>
> Regards,
> Sven
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190108/64d5d1f1/attachment.html>
More information about the fpc-pascal
mailing list