Преглед изворни кода

* give again an error for "in" operations on incompatible set
elements/sets after introduction of support for "longint in set"

git-svn-id: trunk@6885 -

Jonas Maebe пре 18 година
родитељ
комит
428306051f
3 измењених фајлова са 33 додато и 0 уклоњено
  1. 1 0
      .gitattributes
  2. 16 0
      compiler/nset.pas
  3. 16 0
      tests/webtbf/tw8528.pp

+ 1 - 0
.gitattributes

@@ -7191,6 +7191,7 @@ tests/webtbf/tw8150f.pp svneol=native#text/plain
 tests/webtbf/tw8150g.pp svneol=native#text/plain
 tests/webtbf/tw8264a.pp svneol=native#text/plain
 tests/webtbf/tw8398.pp svneol=native#text/plain
+tests/webtbf/tw8528.pp svneol=native#text/plain
 tests/webtbf/uw0744.pp svneol=native#text/plain
 tests/webtbf/uw0840a.pp svneol=native#text/plain
 tests/webtbf/uw0840b.pp svneol=native#text/plain

+ 16 - 0
compiler/nset.pas

@@ -268,6 +268,22 @@ implementation
                inserttypeconv(left,s32inttype)
              else
                inserttypeconv(left,u32inttype);
+           end
+         else if assigned(tsetdef(right.resultdef).elementdef) and
+                 not(is_integer(tsetdef(right.resultdef).elementdef) and
+                     is_integer(left.resultdef)) then
+           begin
+             { Dummy type conversion to check things like                }
+             { 'char in set_of_byte'. Can't use is_subequal because that }
+             { will fail for 'widechar in set_of_char'                   }
+             { Can't use the type conversion for integers because then   }
+             { "longint in set_of_byte" will give a range check error    }
+             { instead of false                                          }
+             { Use a copy of left in case the typeconv node would modify }
+             { left directly (since we need the original left)           }
+             t := ctypeconvnode.create(left.getcopy,tsetdef(right.resultdef).elementdef);
+             typecheckpass(t);
+             t.free;
            end;
 
          { empty set then return false }

+ 16 - 0
tests/webtbf/tw8528.pp

@@ -0,0 +1,16 @@
+{ %fail }
+
+program test;
+
+{$mode objfpc}{$H+}
+
+const
+  AllowedCharSet: set of Byte = [48..60];
+
+var
+  s: string;
+begin
+  s := 'test0';
+  if s[5] in AllowedCharSet then
+    Writeln('huh?');
+end.