From ea888839154a2e81e8807cfdff4bd55aee2f7463 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 8 Jan 2010 10:54:35 +0000 Subject: [PATCH] compiler: fix access to static class fields from the static class methods + extended test git-svn-id: trunk@14574 - --- compiler/pexpr.pas | 11 ++++++++--- tests/test/tstatic1.pp | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index eaf9483f57..d6ca708cec 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -847,7 +847,7 @@ implementation begin 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)) + p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef._class)) else p1:=load_self_node; { We are calling a member } @@ -1383,9 +1383,14 @@ implementation if is_member_read(srsym,srsymtable,p1,hdef) then begin { if the field was originally found in an } - { objectsymtable, it means it's part of self } + { objectsymtable, it means it's part of self + if only method from which it was called is + not class static } if (srsymtable.symtabletype=ObjectSymtable) then - p1:=load_self_node; + if (assigned(current_procinfo) and ([po_staticmethod,po_classmethod] <= current_procinfo.procdef.procoptions)) then + p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef._class)) + else + p1:=load_self_node; { now, if the field itself is part of an objectsymtab } { (it can be even if it was found in a withsymtable, } { e.g., "with classinstance do field := 5"), then } diff --git a/tests/test/tstatic1.pp b/tests/test/tstatic1.pp index 5e24688c37..17a5884f28 100644 --- a/tests/test/tstatic1.pp +++ b/tests/test/tstatic1.pp @@ -6,6 +6,8 @@ program tstatic1; type TSomeClass = class + private + {$ifndef fpc}class var{$endif}FSomethingStatic: Integer; {$ifdef fpc}static;{$endif} public class procedure SomeClassMethod(A: Integer); class procedure SomeStaticMethod(A: Integer); static; @@ -22,9 +24,11 @@ end; class procedure TSomeClass.SomeStaticMethod(A: Integer); {$ifdef fpc} static; {$endif} begin WriteLn('TSomeClass.SomeStaticMethod: ', A); + WriteLn('TSomeClass.FSomethingStatic: ', FSomethingStatic); SomeClassMethod(A + 1); end; begin + TSomeClass.FSomethingStatic := 4; TSomeClass.SomeStaticMethod(1); end. \ No newline at end of file