From 4d79a44e4c36fe664c8641fa9ed1d4856c694d13 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 17 Jan 2013 07:30:00 +0000 Subject: [PATCH] compiler: don't create loadvmtaddrnode for record references, they have no VMT (fixes bug #23130) git-svn-id: trunk@23417 - --- .gitattributes | 1 + compiler/nmem.pas | 3 +-- compiler/pexpr.pas | 10 ++++++++-- tests/webtbs/tw23130.pp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/webtbs/tw23130.pp diff --git a/.gitattributes b/.gitattributes index 5c1b1bf75f..e6130a91a5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13105,6 +13105,7 @@ tests/webtbs/tw2305.pp svneol=native#text/plain tests/webtbs/tw2306.pp svneol=native#text/plain tests/webtbs/tw2307.pp svneol=native#text/plain tests/webtbs/tw2311.pp svneol=native#text/plain +tests/webtbs/tw23130.pp svneol=native#text/pascal tests/webtbs/tw23136.pp svneol=native#text/pascal tests/webtbs/tw2317.pp svneol=native#text/plain tests/webtbs/tw2318.pp svneol=native#text/plain diff --git a/compiler/nmem.pas b/compiler/nmem.pas index 0fc18950a2..2098ce291a 100644 --- a/compiler/nmem.pas +++ b/compiler/nmem.pas @@ -168,8 +168,7 @@ implementation case left.resultdef.typ of classrefdef : resultdef:=left.resultdef; - objectdef, - recorddef: + objectdef: { access to the classtype while specializing? } if (df_generic in left.resultdef.defoptions) then begin diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index b7285745ff..cf686bd87e 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -923,7 +923,10 @@ implementation begin { We are calling from the static class method which has no self node } if assigned(current_procinfo) and current_procinfo.procdef.no_self_node then - p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef.struct)) + if st.symtabletype=recordsymtable then + p1:=ctypenode.create(current_procinfo.procdef.struct) + else + p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef.struct)) else p1:=load_self_node; { We are calling a member } @@ -2445,7 +2448,10 @@ implementation if assigned(current_structdef) and (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or (sp_static in srsym.symoptions)) then - p1:=cloadvmtaddrnode.create(ctypenode.create(hdef)) + if srsymtable.symtabletype=recordsymtable then + p1:=ctypenode.create(hdef) + else + p1:=cloadvmtaddrnode.create(ctypenode.create(hdef)) else if assigned(current_procinfo) and current_procinfo.procdef.no_self_node then p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef.struct)) diff --git a/tests/webtbs/tw23130.pp b/tests/webtbs/tw23130.pp new file mode 100644 index 0000000000..9ebe0ffa43 --- /dev/null +++ b/tests/webtbs/tw23130.pp @@ -0,0 +1,34 @@ +program tw23130; +{$MODE DELPHI} + +type + TFunction = function (const arg: TArgument): TResult; + + TWrapper = record + class function Z(const arg: Integer): Boolean; static; + class procedure W; static; + end; + + TWrapper2 = class + procedure ZZ(f: TFunction); + end; + +class function TWrapper.Z(const arg: Integer): Boolean; +begin + Result := arg < 0; +end; + +class procedure TWrapper.W; +begin + with TWrapper2.Create do begin + ZZ(@Z); { Replace with @TWrapper.Z to get rid of the error } + Free; + end; +end; + +procedure TWrapper2.ZZ(f: TFunction); +begin +end; + +begin +end.