* forbid access to properties in class methods

* readability fix

git-svn-id: trunk@11838 -
This commit is contained in:
florian 2008-09-28 20:16:13 +00:00
parent c79e23c5eb
commit 57f3e2f40a
3 changed files with 36 additions and 16 deletions

1
.gitattributes vendored
View File

@ -6566,6 +6566,7 @@ tests/tbf/tb0209.pp svneol=native#text/plain
tests/tbf/tb0210.pp svneol=native#text/plain
tests/tbf/tb0211.pp svneol=native#text/plain
tests/tbf/tb0212.pp svneol=native#text/plain
tests/tbf/tb0213.pp svneol=native#text/plain
tests/tbf/ub0115.pp svneol=native#text/plain
tests/tbf/ub0149.pp svneol=native#text/plain
tests/tbf/ub0158a.pp svneol=native#text/plain

View File

@ -1568,6 +1568,8 @@ implementation
{ property of a class/object? }
if is_member_read(srsym,srsymtable,p1,hdef) then
begin
if (srsymtable.symtabletype=ObjectSymtable) then
p1:=load_self_node;
{ not srsymtable.symtabletype since that can be }
{ withsymtable as well }
if (srsym.owner.symtabletype=ObjectSymtable) then
@ -2232,22 +2234,23 @@ implementation
check_hints(srsym,srsym.symoptions);
{ load the procdef from the inherited class and
not from self }
if srsym.typ in [procsym,propertysym] then
begin
if (srsym.typ = procsym) then
begin
hdef:=hclassdef;
if (po_classmethod in current_procinfo.procdef.procoptions) or
(po_staticmethod in current_procinfo.procdef.procoptions) then
hdef:=tclassrefdef.create(hdef);
p1:=ctypenode.create(hdef);
end;
end
else
begin
Message(parser_e_methode_id_expected);
p1:=cerrornode.create;
end;
case srsym.typ of
procsym:
begin
hdef:=hclassdef;
if (po_classmethod in current_procinfo.procdef.procoptions) or
(po_staticmethod in current_procinfo.procdef.procoptions) then
hdef:=tclassrefdef.create(hdef);
p1:=ctypenode.create(hdef);
end;
propertysym:
;
else
begin
Message(parser_e_methode_id_expected);
p1:=cerrornode.create;
end;
end;
do_member_read(hclassdef,getaddr,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
end
else

16
tests/tbf/tb0213.pp Normal file
View File

@ -0,0 +1,16 @@
{ %fail }
{$mode objfpc}
type
tc1 = class
fp : longint;
class procedure p;
property prop : longint read fp;
end;
class procedure tc1.p;
begin
writeln(prop);
end;
begin
end.