Bladeren bron

Fix for Mantis #24453. Check for nested types after a specialization. Additionally check correctly whether a type is really a generic before accepting it when parsing a generic.

pgenutil.pas, generate_specialization:
  * use "is_generic" instead of "df_generic in defoptions" as nested non generic types will have that flag set as well and thus would be acceptable for the "<...>" notation although no generic version of it exists
ptype.pas, single_type:
  * check for nested types after doing a specialization

+ added tests (one for now working case and one for now forbidden case)

git-svn-id: trunk@25578 -
svenbarth 12 jaren geleden
bovenliggende
commit
fb8b0e7a27
5 gewijzigde bestanden met toevoegingen van 99 en 1 verwijderingen
  1. 2 0
      .gitattributes
  2. 1 1
      compiler/pgenutil.pas
  3. 1 0
      compiler/ptype.pas
  4. 48 0
      tests/webtbf/tw24453.pp
  5. 47 0
      tests/webtbs/tw24453.pp

+ 2 - 0
.gitattributes

@@ -12461,6 +12461,7 @@ tests/webtbf/tw2414.pp svneol=native#text/plain
 tests/webtbf/tw24184.pp svneol=native#text/plain
 tests/webtbf/tw24428.pp svneol=native#text/plain
 tests/webtbf/tw24428a.pp svneol=native#text/plain
+tests/webtbf/tw24453.pp svneol=native#text/pascal
 tests/webtbf/tw24495.pp svneol=native#text/pascal
 tests/webtbf/tw24588.pp svneol=native#text/pascal
 tests/webtbf/tw2478.pp svneol=native#text/plain
@@ -13569,6 +13570,7 @@ tests/webtbs/tw2432.pp svneol=native#text/plain
 tests/webtbs/tw2435.pp svneol=native#text/plain
 tests/webtbs/tw2438.pp svneol=native#text/plain
 tests/webtbs/tw2442.pp svneol=native#text/plain
+tests/webtbs/tw24453.pp svneol=native#text/pascal
 tests/webtbs/tw24458.pp svneol=native#text/pascal
 tests/webtbs/tw24486.pp svneol=native#text/pascal
 tests/webtbs/tw2452.pp svneol=native#text/plain

+ 1 - 1
compiler/pgenutil.pas

@@ -430,7 +430,7 @@ uses
             if not errorrecovery and
                 (not assigned(tt) or (tt.typ=undefineddef)) then
               begin
-                if (symname='') and (df_generic in genericdef.defoptions) then
+                if (symname='') and genericdef.is_generic then
                   { this happens in non-Delphi modes }
                   tt:=genericdef
                 else

+ 1 - 0
compiler/ptype.pas

@@ -455,6 +455,7 @@ implementation
             if def.typ=forwarddef then
               def:=ttypesym(srsym).typedef;
             generate_specialization(def,stoParseClassParent in options,'');
+            parse_nested_types(def,stoIsForwardDef in options,nil);
           end
         else
           begin

+ 48 - 0
tests/webtbf/tw24453.pp

@@ -0,0 +1,48 @@
+{ %FAIL }
+
+unit tw24453;
+
+{$mode delphi}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils;
+
+type
+
+  { TIterator }
+
+  TIterator<T> = class
+  end;
+
+  TAncestor<T> = class
+  public type
+    TAncestorIterator = class(TIterator<T>)
+    end;
+  end;
+
+  TTestClass<T> = class(TAncestor<T>)
+  private
+    // this compiler recognise
+    fAncIterator: TAncestor<T>.TAncestorIterator;
+  protected
+    // this however does not compile, compiler error is
+    // ugenericsnestedclassdeclaration.pas(29,39) Fatal: Syntax error, ";" expected but "." found
+    // the same problem as with result type is  with arguments of methods aswell
+
+    //function GetIterator: TAncestor<T>.TAncestorIterator;
+
+    // this compile, but not compatible with delphi (at least with delphi XE2, which I am using)
+    function GetIterator: TAncestorIterator<T>;
+  end;
+
+implementation
+
+function TTestClass<T>.GetIterator: TAncestorIterator<T>;
+begin
+  Result := fAncIterator;
+end;
+
+end.
+

+ 47 - 0
tests/webtbs/tw24453.pp

@@ -0,0 +1,47 @@
+unit tw24453;
+
+{$mode delphi}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils;
+
+type
+
+  { TIterator }
+
+  TIterator<T> = class
+  end;
+
+  TAncestor<T> = class
+  public type
+    TAncestorIterator = class(TIterator<T>)
+    end;
+  end;
+
+  TTestClass<T> = class(TAncestor<T>)
+  private
+    // this compiler recognise
+    fAncIterator: TAncestor<T>.TAncestorIterator;
+  protected
+    // this however does not compile, compiler error is
+    // ugenericsnestedclassdeclaration.pas(29,39) Fatal: Syntax error, ";" expected but "." found
+    // the same problem as with result type is  with arguments of methods aswell
+
+    function GetIterator: TAncestor<T>.TAncestorIterator;
+
+
+    // this compile, but not compatible with delphi (at least with delphi XE2, which I am using)
+    //function GetIterator: TAncestorIterator<T>;
+  end;
+
+implementation
+
+function TTestClass<T>.GetIterator: TAncestor<T>.TAncestorIterator;
+begin
+  Result := fAncIterator;
+end;
+
+end.
+