瀏覽代碼

compiler: load methodpointer for static class methods - fixes internal error 200305061 when some class member is called inside the class static method + test

git-svn-id: trunk@14571 -
paul 15 年之前
父節點
當前提交
67ae263dd9
共有 3 個文件被更改,包括 37 次插入6 次删除
  1. 1 0
      .gitattributes
  2. 6 6
      compiler/pexpr.pas
  3. 30 0
      tests/test/tstatic1.pp

+ 1 - 0
.gitattributes

@@ -9220,6 +9220,7 @@ tests/test/tset6.pp svneol=native#text/plain
 tests/test/tset7.pp svneol=native#text/plain
 tests/test/tsetsize.pp svneol=native#text/plain
 tests/test/tstack.pp svneol=native#text/plain
+tests/test/tstatic1.pp svneol=native#text/pascal
 tests/test/tstprocv.pp svneol=native#text/plain
 tests/test/tstring1.pp svneol=native#text/plain
 tests/test/tstring10.pp svneol=native#text/plain

+ 6 - 6
compiler/pexpr.pas

@@ -845,7 +845,11 @@ implementation
                end;
              ObjectSymtable :
                begin
-                 p1:=load_self_node;
+                 if (assigned(current_procinfo) and ([po_staticmethod,po_classmethod] <= current_procinfo.procdef.procoptions)) then
+                   { We are calling from the static class method which has no self node }
+                   p1 := cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef._class))
+                 else
+                   p1:=load_self_node;
                  { We are calling a member }
                  maybe_load_methodpointer:=true;
                end;
@@ -871,12 +875,8 @@ implementation
 
          { when it is a call to a member we need to load the
            methodpointer first
-           (except if we are in a static class method)
          }
-         membercall:=
-           not(assigned(current_procinfo) and
-               ([po_staticmethod,po_classmethod] <= current_procinfo.procdef.procoptions)) and
-           maybe_load_methodpointer(st,p1);
+         membercall:=maybe_load_methodpointer(st,p1);
 
          { When we are expecting a procvar we also need
            to get the address in some cases }

+ 30 - 0
tests/test/tstatic1.pp

@@ -0,0 +1,30 @@
+program tstatic1;
+{$APPTYPE console}
+{$ifdef fpc}
+  {$mode delphi}{$H+}
+{$endif}
+
+type
+  TSomeClass = class
+  public
+    class procedure SomeClassMethod(A: Integer);
+    class procedure SomeStaticMethod(A: Integer); static;
+  end;
+
+{ TSomeClass }
+
+class procedure TSomeClass.SomeClassMethod(A: Integer);
+begin
+  WriteLn('TSomeClass.SomeClassMethod: ', A);
+end;
+
+// for now fpc requires 'static' modifiers also in the class implementation
+class procedure TSomeClass.SomeStaticMethod(A: Integer); {$ifdef fpc} static; {$endif}
+begin
+  WriteLn('TSomeClass.SomeStaticMethod: ', A);
+  SomeClassMethod(A + 1);
+end;
+
+begin
+  TSomeClass.SomeStaticMethod(1);
+end.