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

This commit is contained in:
florian 2024-09-17 23:01:48 +02:00
parent 4ed3e6d002
commit 76fc3275bc
3 changed files with 16 additions and 3 deletions

View File

@ -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:='';

View File

@ -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
tests/webtbs/tw40890.pp Normal file
View File

@ -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.