From d499163ef5397027eeb93c3f74499ee0f775d103 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Tue, 6 Dec 2016 22:26:53 +0000 Subject: [PATCH] * provisional fix for Mantis #31076: fail gracefully instead of with an internal error if a generic method is declared inside a generic class or record. This will change once we support nested generics however. * adjusted error message to reflect that we're not only dealing with generic classes + added test; note: it's added in webtbs, cause the test will loose its %FAIL attribute in the future git-svn-id: trunk@35079 - --- .gitattributes | 1 + compiler/msg/errore.msg | 4 ++-- compiler/pdecsub.pas | 3 +++ tests/webtbs/tw31076.pp | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw31076.pp diff --git a/.gitattributes b/.gitattributes index d37ee33d8a..ddae172ffe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15292,6 +15292,7 @@ tests/webtbs/tw30978a.pp svneol=native#text/pascal tests/webtbs/tw3101.pp svneol=native#text/plain tests/webtbs/tw31029.pp svneol=native#text/pascal tests/webtbs/tw3104.pp svneol=native#text/plain +tests/webtbs/tw31076.pp svneol=native#text/pascal tests/webtbs/tw3109.pp svneol=native#text/plain tests/webtbs/tw3111.pp svneol=native#text/plain tests/webtbs/tw3113.pp svneol=native#text/plain diff --git a/compiler/msg/errore.msg b/compiler/msg/errore.msg index ef6f2db618..4ac3a6ad29 100644 --- a/compiler/msg/errore.msg +++ b/compiler/msg/errore.msg @@ -1393,11 +1393,11 @@ parser_e_no_procvarnested_const=03296_E_Typed constants of the type 'procedure i % procedural variable contains a reference to a nested procedure/function. % Therefore such typed constants can only be initialized with global % functions/procedures since these do not require a parent frame pointer. -parser_f_no_generic_inside_generic=03297_F_Declaration of generic class inside another generic class is not allowed +parser_f_no_generic_inside_generic=03297_F_Declaration of generic inside another generic is not allowed % At the moment, scanner supports recording of only one token buffer at the time % (guarded by internal error 200511173 in tscannerfile.startrecordtokens). % Since generics are implemented by recording tokens, it is not possible to -% have declaration of generic class inside another generic class. +% have declaration of a generic (type or method) inside another generic. parser_e_forward_intf_declaration_must_be_resolved=03298_E_Forward declaration "$1" must be resolved before a class can conform to or implement it % An Objective-C protocol or Java Interface must be fully defined before classes can conform to it. % This error occurs in the following situation (example for Objective-C, but the same goes for Java interfaces): diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index 1c8b8dd472..1e80abf03e 100644 --- a/compiler/pdecsub.pas +++ b/compiler/pdecsub.pas @@ -911,6 +911,9 @@ implementation exit; end; + if assigned(genericparams) and assigned(current_genericdef) then + Message(parser_f_no_generic_inside_generic); + { method ? } srsym:=nil; if not assigned(astruct) and diff --git a/tests/webtbs/tw31076.pp b/tests/webtbs/tw31076.pp new file mode 100644 index 0000000000..8eedd26ec5 --- /dev/null +++ b/tests/webtbs/tw31076.pp @@ -0,0 +1,19 @@ +{ %FAIL } + +program tw31076; + +{$mode objfpc} + +type + generic TFClass = class + generic function Res(): TF; // <<-- + end; + + generic function TFClass.Res: TF; + begin + + end; + +begin + +end.