Browse Source

--- Merging r29482 into '.':
U compiler/symtable.pas
A tests/webtbs/tw26483.pp
--- Merging r29484 into '.':
U compiler/nutils.pas
A tests/tbf/tb0250.pp
A tests/webtbs/tw26481.pp

# revisions: 29482,29484

git-svn-id: branches/fixes_3_0@29715 -

marco 10 years ago
parent
commit
092d60806d
6 changed files with 131 additions and 6 deletions
  1. 3 0
      .gitattributes
  2. 37 0
      compiler/nutils.pas
  3. 12 6
      compiler/symtable.pas
  4. 22 0
      tests/tbf/tb0250.pp
  5. 33 0
      tests/webtbs/tw26481.pp
  6. 24 0
      tests/webtbs/tw26483.pp

+ 3 - 0
.gitattributes

@@ -9738,6 +9738,7 @@ tests/tbf/tb0246.pp svneol=native#text/pascal
 tests/tbf/tb0247.pp svneol=native#text/pascal
 tests/tbf/tb0248.pp svneol=native#text/pascal
 tests/tbf/tb0249.pp svneol=native#text/pascal
+tests/tbf/tb0250.pp svneol=native#text/pascal
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain
@@ -14155,7 +14156,9 @@ tests/webtbs/tw2643.pp svneol=native#text/plain
 tests/webtbs/tw2645.pp svneol=native#text/plain
 tests/webtbs/tw26467.pp svneol=native#text/pascal
 tests/webtbs/tw2647.pp svneol=native#text/plain
+tests/webtbs/tw26481.pp svneol=native#text/pascal
 tests/webtbs/tw26482.pp svneol=native#text/pascal
+tests/webtbs/tw26483.pp svneol=native#text/pascal
 tests/webtbs/tw2649.pp svneol=native#text/plain
 tests/webtbs/tw2651.pp svneol=native#text/plain
 tests/webtbs/tw26536.pp svneol=native#text/plain

+ 37 - 0
compiler/nutils.pas

@@ -1043,6 +1043,41 @@ implementation
 
 
     function handle_staticfield_access(sym: tsym; nested: boolean; var p1: tnode): boolean;
+
+      function handle_generic_staticfield_access:boolean;
+        var
+          tmp : tstoreddef;
+          pd : tprocdef;
+        begin
+          { in case we have a specialization inside a generic (thus the static var sym does not
+            exist) we simply simulate a non static access to avoid unnecessary errors }
+          if assigned(sym.owner.defowner) and (df_specialization in tstoreddef(sym.owner.defowner).defoptions) then
+            begin
+              tmp:=tstoreddef(sym.owner.defowner);
+              while assigned(tmp) do
+                begin
+                  if df_generic in tmp.defoptions then
+                    begin
+                      p1.free;
+                      if assigned(current_procinfo) then
+                        begin
+                          pd:=current_procinfo.get_normal_proc.procdef;
+                          if assigned(pd) and pd.no_self_node then
+                            p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
+                          else
+                            p1:=load_self_node;
+                        end
+                      else
+                        p1:=load_self_node;
+                      p1:=csubscriptnode.create(sym,p1);
+                      exit(true);
+                    end;
+                  tmp:=tstoreddef(tmp.owner.defowner);
+                end;
+            end;
+          result:=false;
+        end;
+
       var
         static_name: shortstring;
         srsymtable: tsymtable;
@@ -1052,6 +1087,8 @@ implementation
         if (sp_static in sym.symoptions) then
           begin
             result:=true;
+            if handle_generic_staticfield_access then
+              exit;
             if not nested then
               static_name:=lower(sym.owner.name^)+'_'+sym.name
             else

+ 12 - 6
compiler/symtable.pas

@@ -2216,6 +2216,7 @@ implementation
     function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tabstractrecorddef):boolean;
       var
         symownerdef : tabstractrecorddef;
+        nonlocalst : tsymtable;
       begin
         result:=false;
 
@@ -2224,17 +2225,22 @@ implementation
            not (symst.symtabletype in [objectsymtable,recordsymtable]) then
           internalerror(200810285);
         symownerdef:=tabstractrecorddef(symst.defowner);
+        { specializations might belong to a localsymtable or parasymtable }
+        nonlocalst:=symownerdef.owner;
+        if tstoreddef(symst.defowner).is_specialization then
+          while nonlocalst.symtabletype in [localsymtable,parasymtable] do
+            nonlocalst:=nonlocalst.defowner.owner;
         case symvisibility of
           vis_private :
             begin
               { private symbols are allowed when we are in the same
                 module as they are defined }
               result:=(
-                       (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
-                       (symownerdef.owner.iscurrentunit)
+                       (nonlocalst.symtabletype in [globalsymtable,staticsymtable]) and
+                       (nonlocalst.iscurrentunit)
                       ) or
                       ( // the case of specialize inside the generic declaration and nested types
-                       (symownerdef.owner.symtabletype in [objectsymtable,recordsymtable]) and
+                       (nonlocalst.symtabletype in [objectsymtable,recordsymtable]) and
                        (
                          assigned(current_structdef) and
                          (
@@ -2286,8 +2292,8 @@ implementation
                 in the current module }
               result:=(
                        (
-                        (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
-                        (symownerdef.owner.iscurrentunit)
+                        (nonlocalst.symtabletype in [globalsymtable,staticsymtable]) and
+                        (nonlocalst.iscurrentunit)
                        ) or
                        (
                         assigned(contextobjdef) and
@@ -2296,7 +2302,7 @@ implementation
                         def_is_related(contextobjdef,symownerdef)
                        ) or
                        ( // the case of specialize inside the generic declaration and nested types
-                        (symownerdef.owner.symtabletype in [objectsymtable,recordsymtable]) and
+                        (nonlocalst.symtabletype in [objectsymtable,recordsymtable]) and
                         (
                           assigned(current_structdef) and
                           (

+ 22 - 0
tests/tbf/tb0250.pp

@@ -0,0 +1,22 @@
+{ %FAIL }
+
+program tb0250;
+
+{$mode delphi}
+
+type
+  TTest<T> = class
+  class var
+    fTest: TClass;
+    procedure Test;
+  end;
+
+procedure TTest<T>.Test;
+begin
+  fTest.ToString;
+end;
+
+begin
+
+end.
+

+ 33 - 0
tests/webtbs/tw26481.pp

@@ -0,0 +1,33 @@
+{ %NORUN }
+
+program tw26481;
+
+{$MODE DELPHI}
+
+type
+  IComparer<T> = interface
+    function Compare(constref Left, Right: T): Integer; overload;
+  end;
+
+  TOrdinalComparer<T, THashFactory> = class(TInterfacedObject, IComparer<T>)
+  protected class var
+    FComparer: IComparer<T>;
+    FTest: TClass;
+  public
+    function Compare(constref Left, Right: T): Integer; virtual; abstract;
+  end;
+
+  TGOrdinalStringComparer<T, THashFactory> = class(TOrdinalComparer<T, THashFactory>)
+  public
+    function Compare(constref ALeft, ARight: T): Integer; override;
+  end;
+
+function TGOrdinalStringComparer<THashFactory, T>.Compare(constref ALeft,
+  ARight: T): Integer;
+begin
+  Result := FComparer.Compare(ALeft, ARight);
+end;
+
+begin
+end.
+

+ 24 - 0
tests/webtbs/tw26483.pp

@@ -0,0 +1,24 @@
+{ %NORUN }
+
+program tw26483;
+
+{$MODE DELPHI}
+
+type
+  TA<T> = class
+  private
+    F: Integer;
+  end;
+
+  TB<T> = class
+    procedure Foo(A: TObject);
+  end;
+
+procedure TB<T>.Foo(A: TObject);
+begin
+  WriteLn(TA<T>(A).F); // p004.Error: identifier idents no member "F"
+end;
+
+begin
+end.
+