ソースを参照

compiler: don't create loadvmtaddrnode for record references, they have no VMT (fixes bug #23130)

git-svn-id: trunk@23417 -
paul 12 年 前
コミット
4d79a44e4c
4 ファイル変更44 行追加4 行削除
  1. 1 0
      .gitattributes
  2. 1 2
      compiler/nmem.pas
  3. 8 2
      compiler/pexpr.pas
  4. 34 0
      tests/webtbs/tw23130.pp

+ 1 - 0
.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

+ 1 - 2
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

+ 8 - 2
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))

+ 34 - 0
tests/webtbs/tw23130.pp

@@ -0,0 +1,34 @@
+program tw23130;
+{$MODE DELPHI}
+
+type
+  TFunction<TArgument, TResult> = 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<Integer, Boolean>);
+  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<Integer, Boolean>);
+begin
+end;
+
+begin
+end.