Selaa lähdekoodia

* 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 -

svenbarth 8 vuotta sitten
vanhempi
commit
d499163ef5
4 muutettua tiedostoa jossa 25 lisäystä ja 2 poistoa
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/msg/errore.msg
  3. 3 0
      compiler/pdecsub.pas
  4. 19 0
      tests/webtbs/tw31076.pp

+ 1 - 0
.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

+ 2 - 2
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):

+ 3 - 0
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

+ 19 - 0
tests/webtbs/tw31076.pp

@@ -0,0 +1,19 @@
+{ %FAIL }
+
+program tw31076;
+
+{$mode objfpc}
+
+type
+   generic TFClass<TC> = class
+      generic function Res<TF>(): TF; // <<--
+   end;
+   
+   generic function TFClass.Res<TF>: TF;
+   begin
+   
+   end;
+
+begin
+
+end.