Browse Source

* fix #39860: even if the block type is not correct for the specialization of a generic routine continue to specialize it to not trigger e.g. an internal error
+ added tests

Sven/Sarah Barth 3 years ago
parent
commit
35958a9b6b
3 changed files with 33 additions and 12 deletions
  1. 5 12
      compiler/pexpr.pas
  2. 14 0
      tests/webtbf/tw39860a.pp
  3. 14 0
      tests/webtbf/tw39860b.pp

+ 5 - 12
compiler/pexpr.pas

@@ -3403,19 +3403,12 @@ implementation
                              if hdef.typ=procdef then
                                begin
                                  if block_type<>bt_body then
-                                   begin
-                                     message(parser_e_illegal_expression);
-                                     srsym:=generrorsym;
-                                     srsymtable:=nil;
-                                   end
+                                   message(parser_e_illegal_expression);
+                                 srsym:=tprocdef(hdef).procsym;
+                                 if assigned(spezcontext.symtable) then
+                                   srsymtable:=spezcontext.symtable
                                  else
-                                   begin
-                                     srsym:=tprocdef(hdef).procsym;
-                                     if assigned(spezcontext.symtable) then
-                                       srsymtable:=spezcontext.symtable
-                                     else
-                                       srsymtable:=srsym.owner;
-                                   end;
+                                   srsymtable:=srsym.owner;
                                end
                              else
                                internalerror(2015061204);

+ 14 - 0
tests/webtbf/tw39860a.pp

@@ -0,0 +1,14 @@
+{ %FAIL }
+
+{$mode objfpc}
+generic function Size<T>: SizeUint;
+begin
+	result := sizeof(T);
+end;
+
+var
+	a: array[0 .. specialize Size<double> - 1] of byte;
+
+begin
+end.
+

+ 14 - 0
tests/webtbf/tw39860b.pp

@@ -0,0 +1,14 @@
+{ %FAIL }
+
+{$mode delphi}
+function Size<T>: SizeUint;
+begin
+	result := sizeof(T);
+end;
+
+var
+	a: array[0 .. Size<double> - 1] of byte;
+
+begin
+end.
+