Browse Source

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

florian 1 year ago
parent
commit
e412f6be55
2 changed files with 27 additions and 0 deletions
  1. 10 0
      compiler/nset.pas
  2. 17 0
      tests/webtbs/tw40745.pp

+ 10 - 0
compiler/nset.pas

@@ -350,6 +350,7 @@ implementation
         t : tnode;
         t : tnode;
       begin
       begin
          result:=nil;
          result:=nil;
+
          { constant evaluation }
          { constant evaluation }
          if (left.nodetype=ordconstn) then
          if (left.nodetype=ordconstn) then
            begin
            begin
@@ -400,6 +401,15 @@ implementation
              typecheckpass(t);
              typecheckpass(t);
              result:=t;
              result:=t;
              exit;
              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;
       end;
       end;
 
 

+ 17 - 0
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.