Parcourir la source

* fix for Mantis #35981: ensure that the "specialize" token is only really used in non-Delphi modes

git-svn-id: trunk@42776 -
svenbarth il y a 6 ans
Parent
commit
b0b2218cca
3 fichiers modifiés avec 43 ajouts et 2 suppressions
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/ptype.pas
  3. 40 0
      tests/webtbf/tw35981.pp

+ 1 - 0
.gitattributes

@@ -16025,6 +16025,7 @@ tests/webtbf/tw35671.pp svneol=native#text/plain
 tests/webtbf/tw35753.pp svneol=native#text/plain
 tests/webtbf/tw3583.pp svneol=native#text/plain
 tests/webtbf/tw35866.pp svneol=native#text/pascal
+tests/webtbf/tw35981.pp svneol=native#text/pascal
 tests/webtbf/tw3626.pp svneol=native#text/plain
 tests/webtbf/tw3631.pp svneol=native#text/plain
 tests/webtbf/tw3643.pp svneol=native#text/plain

+ 2 - 2
compiler/ptype.pas

@@ -359,7 +359,7 @@ implementation
          if checkcurrentrecdef and
             try_parse_structdef_nested_type(def,current_structdef,isforwarddef) then
            exit;
-         if not allowunitsym and (idtoken=_SPECIALIZE) then
+         if not allowunitsym and not (m_delphi in current_settings.modeswitches) and (idtoken=_SPECIALIZE) then
            begin
              consume(_ID);
              is_specialize:=true;
@@ -490,7 +490,7 @@ implementation
 
                _ID:
                  begin
-                   if try_to_consume(_SPECIALIZE) then
+                   if not (m_delphi in current_settings.modeswitches) and try_to_consume(_SPECIALIZE) then
                      begin
                        if ([stoAllowSpecialization,stoAllowTypeDef] * options = []) then
                          begin

+ 40 - 0
tests/webtbf/tw35981.pp

@@ -0,0 +1,40 @@
+{ %FAIL }
+
+program tw35981;
+
+{$mode Delphi}
+
+uses Classes;
+
+type
+  TFoo<T: TPersistent> = class(TPersistent)
+  public
+    C: T;
+    constructor Create;
+    destructor Destroy; override;
+  end;
+
+  constructor TFoo<T>.Create;
+  begin
+    inherited Create;
+    C := T.Create;
+  end;
+
+  destructor TFoo<T>.Destroy;
+  begin
+    C.Free;
+    inherited Destroy;
+  end;
+
+  // note the *working* specialize here, in {$mode Delphi} !!!
+  function Test<T: TPersistent>: specialize TFoo<T>;
+  begin
+    Result := TFoo<T>.Create;
+  end;
+
+begin
+  with Test<TStrings> do begin
+    WriteLn(C.ClassName);
+    Free;
+  end;
+end.