From fb8b0e7a279e6b0bb649a80c575d70f912ccd46c Mon Sep 17 00:00:00 2001 From: svenbarth Date: Thu, 26 Sep 2013 09:21:28 +0000 Subject: [PATCH] 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 - --- .gitattributes | 2 ++ compiler/pgenutil.pas | 2 +- compiler/ptype.pas | 1 + tests/webtbf/tw24453.pp | 48 +++++++++++++++++++++++++++++++++++++++++ tests/webtbs/tw24453.pp | 47 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/webtbf/tw24453.pp create mode 100644 tests/webtbs/tw24453.pp diff --git a/.gitattributes b/.gitattributes index a2396980b3..d34971c7e6 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index 97bbb20c89..9f73dd46b6 100644 --- a/compiler/pgenutil.pas +++ b/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 diff --git a/compiler/ptype.pas b/compiler/ptype.pas index 210faf35ee..84cc10450e 100644 --- a/compiler/ptype.pas +++ b/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 diff --git a/tests/webtbf/tw24453.pp b/tests/webtbf/tw24453.pp new file mode 100644 index 0000000000..6ab955b169 --- /dev/null +++ b/tests/webtbf/tw24453.pp @@ -0,0 +1,48 @@ +{ %FAIL } + +unit tw24453; + +{$mode delphi}{$H+} + +interface + +uses + Classes, SysUtils; + +type + + { TIterator } + + TIterator = class + end; + + TAncestor = class + public type + TAncestorIterator = class(TIterator) + end; + end; + + TTestClass = class(TAncestor) + private + // this compiler recognise + fAncIterator: TAncestor.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.TAncestorIterator; + + // this compile, but not compatible with delphi (at least with delphi XE2, which I am using) + function GetIterator: TAncestorIterator; + end; + +implementation + +function TTestClass.GetIterator: TAncestorIterator; +begin + Result := fAncIterator; +end; + +end. + diff --git a/tests/webtbs/tw24453.pp b/tests/webtbs/tw24453.pp new file mode 100644 index 0000000000..3d82482cab --- /dev/null +++ b/tests/webtbs/tw24453.pp @@ -0,0 +1,47 @@ +unit tw24453; + +{$mode delphi}{$H+} + +interface + +uses + Classes, SysUtils; + +type + + { TIterator } + + TIterator = class + end; + + TAncestor = class + public type + TAncestorIterator = class(TIterator) + end; + end; + + TTestClass = class(TAncestor) + private + // this compiler recognise + fAncIterator: TAncestor.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.TAncestorIterator; + + + // this compile, but not compatible with delphi (at least with delphi XE2, which I am using) + //function GetIterator: TAncestorIterator; + end; + +implementation + +function TTestClass.GetIterator: TAncestor.TAncestorIterator; +begin + Result := fAncIterator; +end; + +end. +