Browse Source

fcl-passrc: resolver: no hint when hiding private method

git-svn-id: trunk@41600 -
Mattias Gaertner 6 years ago
parent
commit
be7e2bb997
2 changed files with 38 additions and 13 deletions
  1. 16 8
      packages/fcl-passrc/src/pasresolver.pp
  2. 22 5
      packages/fcl-passrc/tests/tcresolver.pas

+ 16 - 8
packages/fcl-passrc/src/pasresolver.pp

@@ -4711,8 +4711,13 @@ begin
           begin
           begin
           // give a hint
           // give a hint
           if Data^.Proc.Parent is TPasMembersType then
           if Data^.Proc.Parent is TPasMembersType then
-            LogMsg(20171118205344,mtHint,nFunctionHidesIdentifier_NonProc,sFunctionHidesIdentifier,
-              [GetElementSourcePosStr(El)],Data^.Proc.ProcType);
+            begin
+            if El.Visibility=visStrictPrivate then
+            else if (El.Visibility=visPrivate) and (El.GetModule<>Data^.Proc.GetModule) then
+            else
+              LogMsg(20171118205344,mtHint,nFunctionHidesIdentifier_NonProc,sFunctionHidesIdentifier,
+                [GetElementSourcePosStr(El)],Data^.Proc.ProcType);
+            end;
           end;
           end;
       fpkMethod:
       fpkMethod:
         // method hides a non proc
         // method hides a non proc
@@ -4800,11 +4805,14 @@ begin
             begin
             begin
             // Delphi/FPC do not give a message when hiding a non virtual method
             // Delphi/FPC do not give a message when hiding a non virtual method
             // -> emit Hint with other message id
             // -> emit Hint with other message id
-            if (Data^.Proc.Parent is TPasMembersType)
-                and (Proc.Visibility<>visStrictPrivate) then
+            if (Data^.Proc.Parent is TPasMembersType) then
               begin
               begin
               ProcScope:=Proc.CustomData as TPasProcedureScope;
               ProcScope:=Proc.CustomData as TPasProcedureScope;
-              if (ProcScope.ImplProc<>nil)  // not abstract, external
+              if (Proc.Visibility=visStrictPrivate)
+                  or ((Proc.Visibility=visPrivate)
+                    and (Proc.GetModule<>Data^.Proc.GetModule)) then
+                // a private private is hidden by definition -> no hint
+              else if (ProcScope.ImplProc<>nil)  // not abstract, external
                   and (not ProcHasImplElements(ProcScope.ImplProc)) then
                   and (not ProcHasImplElements(ProcScope.ImplProc)) then
                 // hidden method has implementation, but no statements -> useless
                 // hidden method has implementation, but no statements -> useless
                 // -> do not give a hint for hiding this useless method
                 // -> do not give a hint for hiding this useless method
@@ -4812,13 +4820,13 @@ begin
               else if (Proc is TPasConstructor)
               else if (Proc is TPasConstructor)
                   and (Data^.Proc.ClassType=Proc.ClassType) then
                   and (Data^.Proc.ClassType=Proc.ClassType) then
                 // do not give a hint for hiding a constructor
                 // do not give a hint for hiding a constructor
-              else if (Proc.Visibility=visPrivate)
-                  and (Proc.GetModule<>Data^.Proc.GetModule) then
-                // a private private is hidden by definition -> no hint
               else
               else
+                begin
+                //writeln('TPasResolver.OnFindProc Proc=',Proc.PathName,' Data^.Proc=',Data^.Proc.PathName,' ',Proc.Visibility);
                 LogMsg(20171118214523,mtHint,
                 LogMsg(20171118214523,mtHint,
                   nFunctionHidesIdentifier_NonVirtualMethod,sFunctionHidesIdentifier,
                   nFunctionHidesIdentifier_NonVirtualMethod,sFunctionHidesIdentifier,
                   [GetElementSourcePosStr(Proc)],Data^.Proc.ProcType);
                   [GetElementSourcePosStr(Proc)],Data^.Proc.ProcType);
+                end;
               end;
               end;
             end;
             end;
           Abort:=true;
           Abort:=true;

+ 22 - 5
packages/fcl-passrc/tests/tcresolver.pas

@@ -9510,21 +9510,38 @@ end;
 
 
 procedure TTestResolver.TestClass_NoHintMethodHidesPrivateMethod;
 procedure TTestResolver.TestClass_NoHintMethodHidesPrivateMethod;
 begin
 begin
-  StartProgram(false);
+  AddModuleWithIntfImplSrc('unit2.pas',
+    LinesToStr([
+    'type',
+    '  TObject = class',
+    '  private',
+    '    procedure DoIt(p: pointer);',
+    '  end;',
+    '']),
+    LinesToStr([
+    'procedure TObject.DoIt(p: pointer);',
+    'begin',
+    '  if p=nil then ;',
+    'end;',
+    '']) );
+  StartProgram(true);
   Add([
   Add([
+  'uses unit2;',
   'type',
   'type',
-  '  TObject = class',
+  '  TAnimal = class',
   '  strict private',
   '  strict private',
-  '    procedure DoIt(p: pointer);',
+  '    procedure Fly(p: pointer);',
   '  end;',
   '  end;',
-  '  TBird = class',
+  '  TBird = class(TAnimal)',
   '    procedure DoIt(i: longint);',
   '    procedure DoIt(i: longint);',
+  '    procedure Fly(b: boolean);',
   '  end;',
   '  end;',
-  'procedure TObject.DoIt(p: pointer);',
+  'procedure TAnimal.Fly(p: pointer);',
   'begin',
   'begin',
   '  if p=nil then ;',
   '  if p=nil then ;',
   'end;',
   'end;',
   'procedure TBird.DoIt(i: longint); begin end;',
   'procedure TBird.DoIt(i: longint); begin end;',
+  'procedure TBird.Fly(b: boolean); begin end;',
   'var b: TBird;',
   'var b: TBird;',
   'begin',
   'begin',
   '  b.DoIt(3);']);
   '  b.DoIt(3);']);