compiler: fix access to static class fields from the static class methods + extended test

git-svn-id: trunk@14574 -
This commit is contained in:
paul 2010-01-08 10:54:35 +00:00
parent 06e604cffd
commit ea88883915
2 changed files with 12 additions and 3 deletions

View File

@ -1383,8 +1383,13 @@ 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
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, }

View File

@ -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.