Sfoglia il codice sorgente

* constrained type parameters are not undefined defs, resolves #37107

git-svn-id: trunk@45457 -
florian 5 anni fa
parent
commit
51da470757
4 ha cambiato i file con 22 aggiunte e 2 eliminazioni
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/defutil.pas
  3. 1 1
      compiler/pexpr.pas
  4. 19 0
      tests/webtbs/tw37107.pp

+ 1 - 0
.gitattributes

@@ -18291,6 +18291,7 @@ tests/webtbs/tw37062.pp svneol=native#text/pascal
 tests/webtbs/tw3708.pp svneol=native#text/plain
 tests/webtbs/tw37095.pp svneol=native#text/plain
 tests/webtbs/tw37095d/uw37095.pp svneol=native#text/plain
+tests/webtbs/tw37107.pp svneol=native#text/pascal
 tests/webtbs/tw3719.pp svneol=native#text/plain
 tests/webtbs/tw3721.pp svneol=native#text/plain
 tests/webtbs/tw3742.pp svneol=native#text/plain

+ 1 - 1
compiler/defutil.pas

@@ -1821,7 +1821,7 @@ implementation
 
     function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
       begin
-        result:=(def.typ=undefineddef);
+        result:=(def.typ=undefineddef) or (df_genconstraint in def.defoptions);
       end;
 
 

+ 1 - 1
compiler/pexpr.pas

@@ -443,7 +443,7 @@ implementation
                   is_open_string(p1.resultdef)
                  )) or
                  { keep the function call if it is a type parameter to avoid arithmetic errors due to constant folding }
-                 (p1.resultdef.typ=undefineddef) then
+                 is_typeparam(p1.resultdef) then
                 begin
                   statement_syssym:=geninlinenode(in_sizeof_x,false,p1);
                   { no packed bit support for these things }

+ 19 - 0
tests/webtbs/tw37107.pp

@@ -0,0 +1,19 @@
+program genTest;
+
+{$IFDEF FPC}{$mode Delphi}{$ENDIF}
+
+type
+  TTest<T: Record> = class(TObject)
+    procedure testit();
+  end;
+
+procedure TTest<T>.testit();
+begin
+  WriteLn('=== ', 1 div SizeOf(T));
+  if SizeOf(T) > 0 then
+    WriteLn('I''m reachable!')
+end;
+  
+begin
+  TTest<Char>.Create().TestIt();
+end.