Symbolic constants: don't range check on use

If these constants are defined with an explicit type, they are already
truncated/checked at that point. If we range check them again on use, we
may get errors because at that point there is no explicit type cast
any more.
This commit is contained in:
Jonas Maebe 2022-04-02 13:23:55 +02:00
parent 31f74f65b0
commit 3da54dcf9f
2 changed files with 26 additions and 1 deletions

View File

@ -328,7 +328,9 @@ implementation
begin
if p.constdef=nil then
internalerror(200403232);
p1:=cordconstnode.create(p.value.valueord,p.constdef,true);
{ no range checking; if it has a fixed type, the necessary value
truncation was already performed at the declaration time }
p1:=cordconstnode.create(p.value.valueord,p.constdef,false);
end;
conststring :
begin

23
tests/tbs/tb0693.pp Normal file
View File

@ -0,0 +1,23 @@
{ %norun }
{$r+}
{$mode delphi}
type
TLanguages = (
lOne,
lTwo,
lThree,
lFour
);
const
LANGUAGE_NONE = TLanguages(255);
var
Lang: TLanguages;
begin
Lang := LANGUAGE_NONE; //line 20
end.