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.