From 35958a9b6b927d8ce9b1d0002ba942e14c6b8422 Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Fri, 12 Aug 2022 14:45:12 +0200 Subject: [PATCH] * 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 --- compiler/pexpr.pas | 17 +++++------------ tests/webtbf/tw39860a.pp | 14 ++++++++++++++ tests/webtbf/tw39860b.pp | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 tests/webtbf/tw39860a.pp create mode 100644 tests/webtbf/tw39860b.pp diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 51d753b848..01b9acebf6 100644 --- a/compiler/pexpr.pas +++ b/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); diff --git a/tests/webtbf/tw39860a.pp b/tests/webtbf/tw39860a.pp new file mode 100644 index 0000000000..d99750d7a4 --- /dev/null +++ b/tests/webtbf/tw39860a.pp @@ -0,0 +1,14 @@ +{ %FAIL } + +{$mode objfpc} +generic function Size: SizeUint; +begin + result := sizeof(T); +end; + +var + a: array[0 .. specialize Size - 1] of byte; + +begin +end. + diff --git a/tests/webtbf/tw39860b.pp b/tests/webtbf/tw39860b.pp new file mode 100644 index 0000000000..d2ffc815fd --- /dev/null +++ b/tests/webtbf/tw39860b.pp @@ -0,0 +1,14 @@ +{ %FAIL } + +{$mode delphi} +function Size: SizeUint; +begin + result := sizeof(T); +end; + +var + a: array[0 .. Size - 1] of byte; + +begin +end. +