+ in on an empty set is always false, resolves #40745

This commit is contained in:
florian 2024-04-19 23:43:05 +02:00
parent 484dab553b
commit e412f6be55
2 changed files with 27 additions and 0 deletions

View File

@ -350,6 +350,7 @@ implementation
t : tnode;
begin
result:=nil;
{ constant evaluation }
if (left.nodetype=ordconstn) then
begin
@ -400,6 +401,15 @@ implementation
typecheckpass(t);
result:=t;
exit;
end
{ ... in [] is always false }
else if is_emptyset(right) and
not(might_have_sideeffects(left,[mhs_exceptions])) then
begin
t:=cordconstnode.create(1, pasbool1type, false);
typecheckpass(t);
result:=t;
exit;
end;
end;

17
tests/webtbs/tw40745.pp Normal file
View File

@ -0,0 +1,17 @@
program test;
{$mode objfpc}
type
TSetOfChar = set of char;
TMyObject=class
class function Method(setofchar: TSetOfChar): Boolean; inline;
end;
class function TMyObject.Method(setofchar: TSetOfChar): Boolean;
var sym: char=#0;
begin
Result:=sym in setofchar;
end;
begin
TMyObject.Method([]);
end.