[fpc-pascal] Constants in generics
Benito van der Zander
benito at benibela.de
Tue Jan 8 23:49:21 CET 2019
that reminds me of https://bugs.freepascal.org/view.php?id=34232
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>>
> 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:
> generic TList<const U:byte> = record
> list: array[0..U-1] of integer; // ERROR: high
> value < low value (0..-1)
> 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
> If not we can always add some flag to tconstsym...
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal