Преглед изворни кода

* fixed calling static class methods from inside other static class methods

git-svn-id: trunk@12866 -
Jonas Maebe пре 16 година
родитељ
комит
da461c5154
4 измењених фајлова са 54 додато и 3 уклоњено
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/ncal.pas
  3. 7 2
      compiler/pexpr.pas
  4. 44 0
      tests/webtbs/tw12242a.pp

+ 1 - 0
.gitattributes

@@ -8746,6 +8746,7 @@ tests/webtbs/tw1223.pp svneol=native#text/plain
 tests/webtbs/tw12233.pp svneol=native#text/plain
 tests/webtbs/tw12237.pp svneol=native#text/plain
 tests/webtbs/tw12242.pp svneol=native#text/plain
+tests/webtbs/tw12242a.pp svneol=native#text/plain
 tests/webtbs/tw12249.pp svneol=native#text/plain
 tests/webtbs/tw12255.pp svneol=native#text/plain
 tests/webtbs/tw1228.pp svneol=native#text/plain

+ 2 - 1
compiler/ncal.pas

@@ -2608,7 +2608,8 @@ implementation
           begin
             { When this is method the methodpointer must be available }
             if (right=nil) and
-               (procdefinition.owner.symtabletype=ObjectSymtable) then
+               (procdefinition.owner.symtabletype=ObjectSymtable) and
+               not([po_staticmethod,po_classmethod] <= procdefinition.procoptions) then
               internalerror(200305061);
           end;
 

+ 7 - 2
compiler/pexpr.pas

@@ -840,8 +840,13 @@ implementation
          aprocdef:=nil;
 
          { when it is a call to a member we need to load the
-           methodpointer first }
-         membercall:=maybe_load_methodpointer(st,p1);
+           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);
 
          { When we are expecting a procvar we also need
            to get the address in some cases }

+ 44 - 0
tests/webtbs/tw12242a.pp

@@ -0,0 +1,44 @@
+{$mode objfpc}
+{$static on}
+
+type
+  tc = class
+    class procedure a; cdecl; static;
+    class procedure b; cdecl; static;
+    procedure c;
+  end;
+
+var
+  ok: boolean;
+
+class procedure tc.a; cdecl; static;
+begin
+  writeln('a');
+  ok:=true;
+end;
+
+
+class procedure tc.b; cdecl; static;
+begin
+  a;
+end;
+
+procedure tc.c;
+begin
+  a;
+end;
+
+var
+  c: tc;
+begin
+  ok:=false;
+  tc.b;
+  if not ok then
+    halt(1);
+  ok:=false;
+  c:=tc.create;
+  c.c;
+  c.free;
+  if not ok then
+    halt(2);
+end.