Browse Source

* handle except blocks as normal code block with regard to specialization of generics, resolves #40890

florian 10 months ago
parent
commit
76fc3275bc
3 changed files with 16 additions and 3 deletions
  1. 2 2
      compiler/pexpr.pas
  2. 1 1
      compiler/pgentype.pas
  3. 13 0
      tests/webtbs/tw40890.pp

+ 2 - 2
compiler/pexpr.pas

@@ -3446,7 +3446,7 @@ implementation
                            else
                              if hdef.typ=procdef then
                                begin
-                                 if block_type<>bt_body then
+                                 if not(block_type in inline_specialization_block_types) then
                                    message(parser_e_illegal_expression);
                                  srsym:=tprocdef(hdef).procsym;
                                  if assigned(spezcontext.symtable) then
@@ -3721,7 +3721,7 @@ implementation
              dopostfix:=false
            else
              if (m_delphi in current_settings.modeswitches) and
-                 (block_type=bt_body) and
+                 (block_type in inline_specialization_block_types) and
                  (token in [_LT,_LSHARPBRACKET]) then
                begin
                  idstr:='';

+ 1 - 1
compiler/pgentype.pas

@@ -31,7 +31,7 @@ uses
   symtype,symbase;
 
 const
-  inline_specialization_block_types = [bt_type,bt_var_type,bt_const_type,bt_body];
+  inline_specialization_block_types = [bt_type,bt_var_type,bt_const_type,bt_body,bt_except];
 
 type
   tspecializationstate = record

+ 13 - 0
tests/webtbs/tw40890.pp

@@ -0,0 +1,13 @@
+{$mode objfpc}
+generic procedure Foo<T>;
+begin
+  WriteLn('Bar');
+end;
+
+begin
+  try
+    specialize Foo<Integer>; // this one works
+  except
+    specialize Foo<Integer>; // Error: Identifier not found "specialize"
+  end;
+end.