Browse Source

* don't attempt to load the VMT of a niln when taking the address of a
class method (mantis #30706)

git-svn-id: trunk@34641 -

Jonas Maebe 8 years ago
parent
commit
233622157c
3 changed files with 27 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/nld.pas
  3. 24 0
      tests/webtbs/tw30706.pp

+ 1 - 0
.gitattributes

@@ -15242,6 +15242,7 @@ tests/webtbs/tw30572.pp svneol=native#text/plain
 tests/webtbs/tw3063.pp svneol=native#text/plain
 tests/webtbs/tw3063.pp svneol=native#text/plain
 tests/webtbs/tw3064.pp svneol=native#text/plain
 tests/webtbs/tw3064.pp svneol=native#text/plain
 tests/webtbs/tw30666.pp svneol=native#text/plain
 tests/webtbs/tw30666.pp svneol=native#text/plain
+tests/webtbs/tw30706.pp svneol=native#text/plain
 tests/webtbs/tw3073.pp svneol=native#text/plain
 tests/webtbs/tw3073.pp svneol=native#text/plain
 tests/webtbs/tw3082.pp svneol=native#text/plain
 tests/webtbs/tw3082.pp svneol=native#text/plain
 tests/webtbs/tw3083.pp svneol=native#text/plain
 tests/webtbs/tw3083.pp svneol=native#text/plain

+ 2 - 1
compiler/nld.pas

@@ -368,7 +368,8 @@ implementation
                  begin
                  begin
                    typecheckpass(left);
                    typecheckpass(left);
                    if (po_classmethod in fprocdef.procoptions) and
                    if (po_classmethod in fprocdef.procoptions) and
-                      is_class(left.resultdef) then
+                      is_class(left.resultdef) and
+                      (left.nodetype<>niln) then
                      begin
                      begin
                        left:=cloadvmtaddrnode.create(left);
                        left:=cloadvmtaddrnode.create(left);
                        typecheckpass(left);
                        typecheckpass(left);

+ 24 - 0
tests/webtbs/tw30706.pp

@@ -0,0 +1,24 @@
+{$mode objfpc}{$H+}
+
+uses SysUtils;
+
+type
+  TMyMethod = procedure (A: Integer) of object;
+
+  TMyClass = class
+    class procedure Foo(A: Integer);
+  end;
+
+class procedure TMyClass.Foo(A: Integer);
+begin
+  Writeln('Got int ', A);
+end;
+
+procedure CallMethod(M: TMyMethod);
+begin
+  M(123);
+end;
+
+begin
+  CallMethod({$ifdef FPC_OBJFPC} @ {$endif} TMyClass(nil).Foo);
+end.