diff --git a/.gitattributes b/.gitattributes index fe6fa72d33..2eae2ebf64 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18599,6 +18599,7 @@ tests/webtbs/tw38069.pp svneol=native#text/pascal tests/webtbs/tw38074.pp svneol=native#text/pascal tests/webtbs/tw38083.pp svneol=native#text/pascal tests/webtbs/tw38122.pp svneol=native#text/pascal +tests/webtbs/tw38122b.pp svneol=native#text/pascal tests/webtbs/tw3814.pp svneol=native#text/plain tests/webtbs/tw38145a.pp svneol=native#text/pascal tests/webtbs/tw38145b.pp svneol=native#text/pascal diff --git a/compiler/ncal.pas b/compiler/ncal.pas index ec31af5f8b..fb1ffb3497 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -4014,8 +4014,27 @@ implementation if methodpointer.nodetype<>typen then begin - { Remove all postfix operators } + { if the value a type helper works on is a derefentiation (before + removing postix operators) we need to pass the original pointer + as Self as the Self value might be changed by the helper } + if is_objectpascal_helper(tdef(procdefinition.owner.defowner)) and + not is_implicit_pointer_object_type(tobjectdef(procdefinition.owner.defowner).extendeddef) then + begin + hpt:=methodpointer; + + hpt:=actualtargetnode(@hpt)^; + if hpt.nodetype=derefn then + begin + tmp:=tderefnode(hpt).left; + tderefnode(hpt).left:=nil; + methodpointer.free; + methodpointer:=tmp; + end; + end; + hpt:=methodpointer; + + { Remove all postfix operators } while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do hpt:=tunarynode(hpt).left; @@ -4038,19 +4057,6 @@ implementation e.g. class reference types account } hpt:=actualtargetnode(@hpt)^; - { if the value a type helper works on is a derefentiation we need to - pass the original pointer as Self as the Self value might be - changed by the helper } - if is_objectpascal_helper(tdef(procdefinition.owner.defowner)) and - not is_implicit_pointer_object_type(tobjectdef(procdefinition.owner.defowner).extendeddef) and - (hpt.nodetype=derefn) then - begin - tmp:=tderefnode(hpt).left; - tderefnode(hpt).left:=nil; - methodpointer.free; - methodpointer:=tmp; - end; - { R.Init then R will be initialized by the constructor, Also allow it for simple loads } if (procdefinition.proctypeoption=potype_constructor) or diff --git a/tests/webtbs/tw38122b.pp b/tests/webtbs/tw38122b.pp new file mode 100644 index 0000000000..b99996612e --- /dev/null +++ b/tests/webtbs/tw38122b.pp @@ -0,0 +1,19 @@ +program tw38122b; +{$mode delphi} +uses sysutils; +type trec=record + i:integer; + end; + + var rec:trec; + prec:^trec; + s: string; +begin + rec.i:=20; + prec:=@rec; + s:=prec.i.tostring; + //writeln(s); + if s<>'20' then + halt(1); +end. +