Ver Fonte

* allow type parameters variables being passed to new/dispose, resolves #23270

git-svn-id: trunk@22963 -
florian há 12 anos atrás
pai
commit
d67f31a0e1
3 ficheiros alterados com 46 adições e 2 exclusões
  1. 1 0
      .gitattributes
  2. 22 2
      compiler/pinline.pas
  3. 23 0
      tests/webtbs/tw23270.pp

+ 1 - 0
.gitattributes

@@ -12985,6 +12985,7 @@ tests/webtbs/tw23185.pp svneol=native#text/pascal
 tests/webtbs/tw2318b.pp svneol=native#text/plain
 tests/webtbs/tw23212.pp svneol=native#text/plain
 tests/webtbs/tw2323.pp svneol=native#text/plain
+tests/webtbs/tw23270.pp svneol=native#text/pascal
 tests/webtbs/tw2328.pp svneol=native#text/plain
 tests/webtbs/tw2332.pp svneol=native#text/plain
 tests/webtbs/tw2351.pp svneol=native#text/plain

+ 22 - 2
compiler/pinline.pas

@@ -159,6 +159,16 @@ implementation
             destructorpos:=current_tokenpos;
             consume(_ID);
 
+            if is_typeparam(p.resultdef) then
+              begin
+                 p.free;
+                 p:=factor(false,false);
+                 p.free;
+                 consume(_RKLAMMER);
+                 new_dispose_statement:=cnothingnode.create;
+                 exit;
+              end;
+
             if (p.resultdef.typ<>pointerdef) then
               begin
                  Message1(type_e_pointer_type_expected,p.resultdef.typename);
@@ -278,8 +288,18 @@ implementation
           begin
              if (p.resultdef.typ<>pointerdef) then
                Begin
-                  Message1(type_e_pointer_type_expected,p.resultdef.typename);
-                  new_dispose_statement:=cerrornode.create;
+                 if is_typeparam(p.resultdef) then
+                   begin
+                      p.free;
+                      consume(_RKLAMMER);
+                      new_dispose_statement:=cnothingnode.create;
+                      exit;
+                   end
+                 else
+                   begin
+                     Message1(type_e_pointer_type_expected,p.resultdef.typename);
+                     new_dispose_statement:=cerrornode.create;
+                   end;
                end
              else
                begin

+ 23 - 0
tests/webtbs/tw23270.pp

@@ -0,0 +1,23 @@
+{$MODE DELPHI}
+
+type
+  TSmallWrapper<TValue> = record
+    Value: TValue;
+  end;
+
+  TWrapper<T> = class
+  strict private
+    class var FSmallWrapper: TSmallWrapper<PInteger>;
+  public
+    class procedure Z; static;
+  end;
+
+class procedure TWrapper<T>.Z;
+begin
+  FSmallWrapper.Value := New(PInteger);
+  Dispose(FSmallWrapper.Value);  { Error: pointer type expected, but ... }
+end;
+
+begin
+  TWrapper<Byte>.Z;
+end.