Lastly, the compiler's first and foremost responsibility is to produce correct code. speed, optimizations or any other concerns are secondary to that one. IOW, optimizations and speed concerns do not justify producing incorrect code.
Non 0/1 values are considered undefined, and any operation on such variable gives an undefined result.
And how do you justify the compiler accepting "ord(b8) := 4;" while rejecting "integer(b8) := 4;", it is rather easy to reject the first one too. Why should the compiler allow "undefined" values ? How can that be justified ? (code wise it's rather simple to disallow those undefined boolean values. However, that is not sufficient, the code the compiler generates needs to be changed because it is incorrect even when the compiler prevents undefined values.)
The reason to leave it that way is optimisation. Trying to close those gaps to assign values to booleans only complicates the RTL and people writing streaming code for booleans, for at best hypothetical gains.
Did optimization (or speed) become more important than correctness ? if correctness still rules the day then a change in FPC is necessary. Bugs are inconvenient and fixing them is usually inconvenient too but, that isn't normally a reason given to leave them uncorrected.
Also,
The documentation states:
Free Pascal supports the Boolean type, with its two predefined possible values True and False.
These are the only two values that can be assigned to a Boolean type.
...
In addition to the simple Boolean type, the additional Boolean16, Boolean32 and Boolean64
types exist. These are in fact integer types, which are assignment-compatible with the simple boolean
type. As an integer, the values for True and False are 1 and 0.
Emphasis mine. The typecasts show that
TRUE and FALSE are most definitely NOT the only two values that can be assigned to a Boolean type.
Now the problem is, the documentation is correct but the compiler is not operating as the spec/documentation requires.
Possible fixes:
a. "amend" the documentation to state the compiler allows values other than TRUE and FALSE for a boolean.
or
b. correct the compiler so it treats booleans correctly.
if (a) then it would be nice to include a warning in the documentation that unpredictable results should be expected in that case. It would also be nice if the compiler emitted a warning stating as much too.
if (b) then the compiler would operate as documented which is a nice plus (correctness: 1, optimizations: do it right first, then do it faster while keeping it right)