From cbe352808a40b5ccd8f34d4c522b39f9b94cd9df Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sun, 20 Dec 2020 22:41:27 +0000 Subject: [PATCH] * fix for Mantis #38238: when creating a copy of a procdef for a procvar set the methodpointer flag also for methods of records + added test git-svn-id: trunk@47826 - --- .gitattributes | 1 + compiler/symdef.pas | 2 +- tests/webtbs/tw38238.pp | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw38238.pp diff --git a/.gitattributes b/.gitattributes index d824e2beb6..45b2a70666 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18613,6 +18613,7 @@ tests/webtbs/tw38164.pp svneol=native#text/pascal tests/webtbs/tw38201.pp svneol=native#text/pascal tests/webtbs/tw38202.pp svneol=native#text/pascal tests/webtbs/tw38225.pp svneol=native#text/pascal +tests/webtbs/tw38238.pp svneol=native#text/pascal tests/webtbs/tw3827.pp svneol=native#text/plain tests/webtbs/tw3829.pp svneol=native#text/plain tests/webtbs/tw3833.pp svneol=native#text/plain diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 58d34343bd..65a2a11bc8 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -5811,7 +5811,7 @@ implementation {$endif} if (typ=procdef) and (newtyp=procvardef) and - (owner.symtabletype=ObjectSymtable) then + (owner.symtabletype in [ObjectSymtable,recordsymtable]) then include(tprocvardef(result).procoptions,po_methodpointer); end; diff --git a/tests/webtbs/tw38238.pp b/tests/webtbs/tw38238.pp new file mode 100644 index 0000000000..a49daef1dc --- /dev/null +++ b/tests/webtbs/tw38238.pp @@ -0,0 +1,56 @@ +program tw38238; + +{$mode objfpc} +{$modeswitch advancedrecords} + +type + TCallback = procedure(AValue: longint) of object; + + TRec = record + Clb: TCallback; + procedure AddCallback(ACallback: TCallback); + procedure TriggerCallback(AValue: longint); + end; + + TRec2 = record + Value: longint; + Rec: TRec; + procedure CLB(AValue: longint); + procedure InitStuff; + end; + +procedure TRec.AddCallback(ACallback: TCallback); +begin + Clb:=ACallback; +end; + +procedure TRec.TriggerCallback(AValue: longint); +begin + if assigned(Clb) then + Clb(AValue); +end; + +procedure TRec2.CLB(AValue: longint); +begin + Value:=AValue; +end; + +procedure TRec2.InitStuff; +begin + Rec.AddCallback(@CLB); +end; + +var + Rec1, Rec2: TRec2; +begin + Rec1.InitStuff; + Rec2.InitStuff; + + Rec1.Rec.TriggerCallback(1234); + Rec2.Rec.TriggerCallback($0943); + + if Rec1.Value<>1234 then + Halt(1); + if Rec2.Value<>$0943 then + Halt(2); +end.