Calculating typed Constants
Original Reporter info from Mantis: AndreasD
-
Reporter name: Andreas Dorn
Original Reporter info from Mantis: AndreasD
- Reporter name: Andreas Dorn
Description:
Since the compiler does use constant folding, the error message below is confusing:
Incompatible types: got "SYSTEM.LongInt" expected "SYSTEM.LongInt
I tried to calculate a typed constant by an simple expression containing another typed constant.
Steps to reproduce:
//The following program causes the compiler to abort:
program test;
const yini2 : LongInt = 16;
yini3 = 3;
yini5:LongInt = yini2 + 3 * yini3;
// Error-position---^
begin;
writeln(yini2);
writeln(yini3);
writeln(yini5);
end.
Additional information:
Replacing the error line with "var yini5:LongInt=yini2+3*yini3;"
will raise the same error, because the compiler handles a typed const the same way as an initiallized var. (p15, ref.pdf)
This error also occures with
{const} yini5:LontInt = yini2;
A 1st workaround is to make yini2 a constant instead of a typed constant.
A 2nd workaround is to use "var yini5:LongInt;" instead, and to calculate in the regular way.
Maybe this error is a resurrection of BugID 0004997.
Mantis conversion info:
- Mantis ID: 10828
- OS: Windows 2k
- OS Build: 5.00.2195
- Platform: Pentium 4 2,6 GHz
- Version: 2.2.0
- Fixed in version: 2.4.0