Browse Source

* allow in-operator to be used on type parameters, resolves #38497

git-svn-id: trunk@48763 -
florian 4 years ago
parent
commit
5a26c58285
3 changed files with 33 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 8 0
      compiler/nset.pas
  3. 24 0
      tests/webtbs/tw38497.pp

+ 1 - 0
.gitattributes

@@ -18674,6 +18674,7 @@ tests/webtbs/tw3841.pp svneol=native#text/plain
 tests/webtbs/tw38412.pp svneol=native#text/pascal
 tests/webtbs/tw38412.pp svneol=native#text/pascal
 tests/webtbs/tw38413.pp svneol=native#text/pascal
 tests/webtbs/tw38413.pp svneol=native#text/pascal
 tests/webtbs/tw38429.pp svneol=native#text/pascal
 tests/webtbs/tw38429.pp svneol=native#text/pascal
+tests/webtbs/tw38497.pp svneol=native#text/pascal
 tests/webtbs/tw3863.pp svneol=native#text/plain
 tests/webtbs/tw3863.pp svneol=native#text/plain
 tests/webtbs/tw3864.pp svneol=native#text/plain
 tests/webtbs/tw3864.pp svneol=native#text/plain
 tests/webtbs/tw3865.pp svneol=native#text/plain
 tests/webtbs/tw3865.pp svneol=native#text/plain

+ 8 - 0
compiler/nset.pas

@@ -247,6 +247,7 @@ implementation
 
 
       begin
       begin
          result:=nil;
          result:=nil;
+
          resultdef:=pasbool1type;
          resultdef:=pasbool1type;
          typecheckpass(right);
          typecheckpass(right);
          set_varstate(right,vs_read,[vsf_must_be_valid]);
          set_varstate(right,vs_read,[vsf_must_be_valid]);
@@ -269,6 +270,13 @@ implementation
          if not assigned(left.resultdef) then
          if not assigned(left.resultdef) then
            internalerror(20021126);
            internalerror(20021126);
 
 
+         { avoid any problems with type parameters later on }
+         if is_typeparam(left.resultdef) or is_typeparam(right.resultdef) then
+           begin
+             resultdef:=cundefinedtype;
+             exit;
+           end;
+
          t:=self;
          t:=self;
          if isbinaryoverloaded(t,[]) then
          if isbinaryoverloaded(t,[]) then
            begin
            begin

+ 24 - 0
tests/webtbs/tw38497.pp

@@ -0,0 +1,24 @@
+program project1;
+
+{$mode delphi}
+
+type
+  TAlphabet = (A, B, C);
+  TAlphabets = set of TAlphabet;
+
+  procedure Test<TEnum, TSet>(E: TEnum; S: TSet);
+  var
+    I: TEnum;
+    B: Boolean;
+  begin
+    B := [E] <= S;
+    if E in S then
+      WriteLn(E);
+    for I := Low(TEnum) to High(TEnum) do
+      if I in S then
+      WriteLn(I);
+  end;
+
+begin
+  Test<TAlphabet, TAlphabets>(A, [A, B]);
+end.