From e412f6be55f9ba2b45c020a240ed467cce5ac28f Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 19 Apr 2024 23:43:05 +0200 Subject: [PATCH] + in on an empty set is always false, resolves #40745 --- compiler/nset.pas | 10 ++++++++++ tests/webtbs/tw40745.pp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/webtbs/tw40745.pp diff --git a/compiler/nset.pas b/compiler/nset.pas index c0f06e5c1b..fa321aa9ed 100644 --- a/compiler/nset.pas +++ b/compiler/nset.pas @@ -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; diff --git a/tests/webtbs/tw40745.pp b/tests/webtbs/tw40745.pp new file mode 100644 index 0000000000..85bf7c596b --- /dev/null +++ b/tests/webtbs/tw40745.pp @@ -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. \ No newline at end of file