Browse Source

+ explanation for the parameters of is_visible_for_object
* fixed accessibility checking for strict_protected (the class
in which the access occurs also has to be related to the
objectdef of which a symbol is accessed) + test

git-svn-id: trunk@22565 -

Jonas Maebe 12 years ago
parent
commit
e9f4b095e1
5 changed files with 84 additions and 2 deletions
  1. 3 0
      .gitattributes
  2. 15 2
      compiler/symtable.pas
  3. 27 0
      tests/test/tsprot.pp
  4. 21 0
      tests/test/usprot1.pp
  5. 18 0
      tests/test/usprot2.pp

+ 3 - 0
.gitattributes

@@ -11310,6 +11310,7 @@ tests/test/tset6.pp svneol=native#text/plain
 tests/test/tset7.pp svneol=native#text/plain
 tests/test/tsetsize.pp svneol=native#text/plain
 tests/test/tshuffle1.pp svneol=native#text/pascal
+tests/test/tsprot.pp svneol=native#text/plain
 tests/test/tstack.pp svneol=native#text/plain
 tests/test/tstatic1.pp svneol=native#text/pascal
 tests/test/tstatic2.pp svneol=native#text/pascal
@@ -11628,6 +11629,8 @@ tests/test/uprocext1.pp svneol=native#text/plain
 tests/test/uprocext2.pp svneol=native#text/plain
 tests/test/urhlp14.pp svneol=native#text/pascal
 tests/test/urhlp17.pp svneol=native#text/pascal
+tests/test/usprot1.pp svneol=native#text/plain
+tests/test/usprot2.pp svneol=native#text/plain
 tests/test/utasout.pp svneol=native#text/plain
 tests/test/uunit1.pp svneol=native#text/plain
 tests/test/uunit2a.pp svneol=native#text/plain

+ 15 - 2
compiler/symtable.pas

@@ -2113,6 +2113,12 @@ implementation
         result:=false;
       end;
 
+    { symst: symboltable that contains the symbol (-> symowner def: record/objectdef in which the symbol is defined)
+      symvisibility: visibility of the symbol
+      contextobjdef: via which def the symbol is accessed, e.g.:
+        fieldname:=1 -> contextobjdef = current_structdef
+        objfield.fieldname:=1 -> contextobjdef = def of objfield
+    }
     function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tabstractrecorddef):boolean;
       var
         symownerdef : tabstractrecorddef;
@@ -2156,9 +2162,16 @@ implementation
           vis_strictprotected :
             begin
                result:=(
+                         { access from nested class }
                          assigned(current_structdef) and
-                         (current_structdef.is_related(symownerdef) or
-                         is_owned_by(current_structdef,symownerdef))
+                         is_owned_by(current_structdef,symownerdef)
+                       ) or
+                       (
+                         { access from child class }
+                         assigned(contextobjdef) and
+                         assigned(current_structdef) and
+                         contextobjdef.is_related(symownerdef) and
+                         current_structdef.is_related(contextobjdef)
                        ) or
                        (
                          { helpers can access strict protected symbols }

+ 27 - 0
tests/test/tsprot.pp

@@ -0,0 +1,27 @@
+{ %fail }
+
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+unit tsprot;
+
+interface
+
+uses
+  usprot1,usprot2;
+
+type
+  tchild2 = class(tbase)
+    f: tchild1;
+    procedure test;
+  end;
+
+implementation
+
+procedure tchild2.test;
+  begin
+    f.pmethod;
+  end;
+
+end.

+ 21 - 0
tests/test/usprot1.pp

@@ -0,0 +1,21 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+unit usprot1;
+
+interface
+
+type
+  tbase = class
+   strict protected
+    procedure pmethod; virtual; overload;
+  end;
+
+implementation
+
+procedure tbase.pmethod;
+begin
+end;
+
+end.

+ 18 - 0
tests/test/usprot2.pp

@@ -0,0 +1,18 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+unit usprot2;
+
+interface
+
+uses
+  usprot1;
+
+type
+  tchild1 = class(tbase)
+  end;
+
+implementation
+
+end.