From 5135b586cb692ca40e08114cc25cab5f709fda76 Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Fri, 26 Aug 2022 17:42:22 +0200 Subject: [PATCH] * fix #39857: don't trash symbols marked as vo_is_internal + added test --- compiler/ngenutil.pas | 2 +- tests/webtbs/tw39857.pp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw39857.pp diff --git a/compiler/ngenutil.pas b/compiler/ngenutil.pas index d4fe95daf1..2e5be5858e 100644 --- a/compiler/ngenutil.pas +++ b/compiler/ngenutil.pas @@ -788,7 +788,7 @@ implementation (vo_is_funcret in tabstractnormalvarsym(p).varoptions) ) ) and - not (vo_is_parentfp in tabstractnormalvarsym(p).varoptions) and + (tabstractnormalvarsym(p).varoptions*[vo_is_parentfp,vo_is_internal]=[]) and not assigned(tabstractnormalvarsym(p).defaultconstsym); end; diff --git a/tests/webtbs/tw39857.pp b/tests/webtbs/tw39857.pp new file mode 100644 index 0000000000..fdde8d85c8 --- /dev/null +++ b/tests/webtbs/tw39857.pp @@ -0,0 +1,31 @@ +{ %OPT = -gt } + +program tw39857; + +{$mode objfpc}{$H+} +{$ModeSwitch anonymousfunctions} +{$ModeSwitch functionreferences} + +type + TProc = reference to procedure; + +procedure problem(aParam1: integer; aParam2: integer; aParam3: TProc); +begin + Writeln(aParam1, aParam2); +end; + +procedure noproblem(aParam1: integer; aParam2: integer; aParam3: IUnknown); +begin + Writeln(aParam1, aParam2); +end; + +procedure test; +begin + noproblem(1, 2, TInterfacedObject.Create); // ok + problem(3,4, nil); // ok + problem(5,6, procedure begin Writeln('x'); end); // aParam3 is trashed +end; + +begin + test; +end.