From 57f3e2f40abb7a121ca94d2e88b030cccec3b8d0 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 28 Sep 2008 20:16:13 +0000 Subject: [PATCH] * forbid access to properties in class methods * readability fix git-svn-id: trunk@11838 - --- .gitattributes | 1 + compiler/pexpr.pas | 35 +++++++++++++++++++---------------- tests/tbf/tb0213.pp | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 tests/tbf/tb0213.pp diff --git a/.gitattributes b/.gitattributes index 5d21379231..fcb72a4d48 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 8b5c8a7f8c..813c4ace6e 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -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 diff --git a/tests/tbf/tb0213.pp b/tests/tbf/tb0213.pp new file mode 100644 index 0000000000..0c62202cfb --- /dev/null +++ b/tests/tbf/tb0213.pp @@ -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.