浏览代码

* forbid access to properties in class methods
* readability fix

git-svn-id: trunk@11838 -

florian 17 年之前
父节点
当前提交
57f3e2f40a
共有 3 个文件被更改,包括 36 次插入16 次删除
  1. 1 0
      .gitattributes
  2. 19 16
      compiler/pexpr.pas
  3. 16 0
      tests/tbf/tb0213.pp

+ 1 - 0
.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

+ 19 - 16
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

+ 16 - 0
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.