Browse Source

* fix #40634 the 2nd: a (strict) protected symbol in a parent class of the owner is supposed to be visible
+ added test

Sven/Sarah Barth 1 year ago
parent
commit
ea102d792f
3 changed files with 66 additions and 2 deletions
  1. 19 2
      compiler/symtable.pas
  2. 20 0
      tests/webtbs/tw40634b.pp
  3. 27 0
      tests/webtbs/uw40634c.pp

+ 19 - 2
compiler/symtable.pas

@@ -3277,6 +3277,23 @@ implementation
         end;
 
       function check_strict_protected:boolean;
+
+        function owner_hierarchy_related(nested,check:tabstractrecorddef):boolean;
+          var
+            owner:tabstractrecorddef;
+          begin
+            result:=true;
+            repeat
+              if def_is_related(nested,check) then
+                exit;
+              if nested.owner.symtabletype in [recordsymtable,objectsymtable] then
+                nested:=tabstractrecorddef(nested.owner.defowner)
+              else
+                break;
+            until not assigned(nested);
+            result:=false;
+          end;
+
         begin
           result:=(
                     { access from nested class (specialization case) }
@@ -3293,7 +3310,7 @@ implementation
                     { access from child class (specialization case) }
                     assigned(contextobjdef) and
                     assigned(curstruct) and
-                    def_is_related(contextobjdef,symownerdef) and
+                    owner_hierarchy_related(contextobjdef,symownerdef) and
                     def_is_related(curstruct,contextobjdef)
                   ) or
                   (
@@ -3304,7 +3321,7 @@ implementation
                       (orgsymownerdef<>symownerdef)
                     ) and
                     assigned(curstruct) and
-                    def_is_related(orgcontextobjdef,orgsymownerdef) and
+                    owner_hierarchy_related(orgcontextobjdef,orgsymownerdef) and
                     def_is_related(curstruct,orgcontextobjdef)
                   ) or
                   (

+ 20 - 0
tests/webtbs/tw40634b.pp

@@ -0,0 +1,20 @@
+{ %NORUN }
+
+program tw40634b;
+{$mode ObjFPC}{$H+}
+uses uw40634c;
+type
+  TFpThreadWorkerItem = class
+  end;
+
+  TFpThreadWorkerQueue = class(specialize TLazThreadedQueue<TFpThreadWorkerItem>)
+  protected type
+    TFpDbgTypedFifoQueue = class(TLazTypedFifoQueue)
+      //function PushItem(const AItem: TFpThreadWorkerItem): Boolean; override;
+    end;
+  end;
+
+
+begin
+end.
+

+ 27 - 0
tests/webtbs/uw40634c.pp

@@ -0,0 +1,27 @@
+unit uw40634c;
+{$mode ObjFPC}{$H+}
+interface
+
+type
+
+  generic TLazFifoQueue<T> = class
+  private
+    FList: array of T;
+    FQueueSize: integer;
+  //protected
+  //  function PushItem(const AItem: TFpThreadWorkerItem): Boolean; virtual;
+  end;
+
+  { TLazThreadedQueue }
+
+  generic TLazThreadedQueue<T> = class
+  protected
+  type
+    TLazTypedFifoQueue = specialize TLazFifoQueue<T>;
+  end;
+
+
+implementation
+
+end.
+