|
|
|
|
|
by badsectoracula
1150 days ago
|
|
The second bit is because you lack the explicit specialization - you must always tell the compiler how to specialize a generic. Personally i prefer to use generics in objfpc mode as you are more explicit that way. However FPC trunk can allow implicit function specialization if you request it with {$modeswitch implicitfunctionspecialization}. Your code compiles with that. The first bit is an interesting case and i wonder why it happens. It seems the root cause is that it considers the two type specializations equivalent as even ignoring the generic functions something like "A:=B" is allowed. I trimmed the code down to this: {$MODE DELPHI}
type
TMatrix<R, C> = record
X: array[R, C] of Double;
end;
type
R1 = 1..3;
R2 = 1..4;
var
A: TMatrix<R1, R2>;
B: TMatrix<R1, R1>;
begin
A:=B;
end.
This is clearly a bug and not intentional behavior as doing the specialization by hand shows an error as expected. Also it seems related to multidimensional arrays as with a single element it also shows an error. Note that the other way (B:=A) doesn't work, so my guess is that at some point the type compatibility comparison only checks if assigning one array would fit memory-wise into the other.I'll check against latest trunk later and if it happens i'll file a bug report. |
|
I also tried
... and that only gives me a runtime error. So maybe those types count as equal anyway?