The free pascal documentation section on Type Aliases
https://www.freepascal.org/docs-html/current/ref/refse19.html#x49-670003.8 discusses the case where the type keyword appears on the right hand side of a type definition:
Type
MyInteger = Type Integer;
and goes on say that to from the point of view of the compiler these are different types, are assignment compatible and then lists the three consequences, the third one being:
They can be used in operator overloads, that is Operator +(A,B : MyInteger) : MyInteger;
In practice, this fails with "Error: impossible operator overload". Is this an error in the documentation or a compiler bug?
Although at first glance there seems to be no point in being able to overload the operators for assignment compatible types, it would be useful to do so for example to constrain the values a type can contain. For example:
type
qbit = type 0..$0F; // In Delphi nybble=0..$F; qbit=type nybble; - more free pascal goodness :o)
TWrapInt = type -50 .. 50;
TConstrainedInt = type -5 .. 55;
operator := (Right: integer) Left: qbit;
begin
Left := Right and $0F; // <--- Unwanted recursion ?
end;
operator := (Right: integer) Left: TWrapInt;
begin
if Right > high(TWrapInt) then
Left := low(TWrapInt) // <--- Unwanted recursion ?
else if Right < low(TWrapInt) then
Left := high(TWrapInt) // <--- Unwanted recursion ?
else
Left := Right; // <--- Unwanted recursion ?
end;
operator := (Right: integer) Left: TConstrainedInt;
begin
if Right > high(TConstrainedInt) then
Left := high(TConstrainedInt) // <--- Unwanted recursion ?
else if Right < low(TWrapInt) then
Left := low(TWrapInt) // <--- Unwanted recursion ?
else
Left := Right; // <--- Unwanted recursion ?
end;
I realise that number of users who would want something like this is (very) limited, so I suppose the answer is that it is a documentation error