On 21/10/2020 21:59, Ryan Joseph via fpc-pascal wrote:
> Is this a bug in generics with default()?
> 
> =====================
> 
> type
>   TEnum = (Unused = '.');
>   generic TSomething<T> = class
>     function Get: T;
>   end; 
>   TEnumeratedSomething = specialize TSomething<TEnum>;
> 
> function TSomething.Get: T;
> begin
>   // Range check error while evaluating constants (0 must be between 46 and 
> 46)
>   exit(Default(T));
> end;

See https://bugs.freepascal.org/view.php?id=34972 for some comments
about Default. So this is a bug in the usage of Default, since Default
cannot be guaranteed to return a valid value for a type.

It is even technically impossible to make Default return a valid value
for every type due to variant records (you could have overlapping
"field1: 1..3;" and "field2: 4..6;").


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to