* better fix and test for #41488

This commit is contained in:
florian 2026-02-08 21:46:56 +01:00
parent 7b790ec5a8
commit 58d2420c1e
2 changed files with 13 additions and 18 deletions

View File

@ -4490,14 +4490,9 @@ implementation
{$endif}
begin
{ create constant 1, ensure the data type is large enough }
if (left.resultdef is tenumdef) then
range_to_type(
min(1,tenumdef(left.resultdef).min),
max(1,tenumdef(left.resultdef).max),hdef)
else
range_to_type(
min(1,torddef(left.resultdef).low),
max(1,torddef(left.resultdef).high),hdef);
range_to_type(
min(1,get_min_value(left.resultdef)),
max(1,get_max_value(left.resultdef)),hdef);
hp:=cordconstnode.create(1,hdef,false);
typecheckpass(hp);
if not is_integer(hp.resultdef) then
@ -5070,14 +5065,9 @@ implementation
else
begin
{ no, create constant 1, ensure the data type is large enough }
if (left.resultdef is tenumdef) then
range_to_type(
min(1,tenumdef(tcallparanode(left).left.resultdef).min),
max(1,tenumdef(tcallparanode(left).left.resultdef).max),hdef)
else
range_to_type(
min(1,torddef(tcallparanode(left).left.resultdef).low),
max(1,torddef(tcallparanode(left).left.resultdef).high),hdef);
range_to_type(
min(1,get_min_value(tcallparanode(left).left.resultdef)),
max(1,get_max_value(tcallparanode(left).left.resultdef)),hdef);
hpp:=cordconstnode.create(1,hdef,false)
end;
typecheckpass(hpp);

View File

@ -4,10 +4,15 @@ type
TTest = 10..20;
var
A: TTest;
S: String;
begin
A := 10;
Inc(A);
Writeln(Succ(A)); // 12
Writeln(Pred(A)); // 10
Str(Succ(A), S); // 12
if S <> '12' then
halt(1);
Str(Pred(A), S); // 10
if S <> '10' then
halt(2);
Dec(A);
end.