mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-16 05:39:22 +02:00
fcl-passrc: resolver: no hint when hiding private method
This commit is contained in:
parent
45f31d949f
commit
48c0169c38
compiler/packages/fcl-passrc
@ -4696,8 +4696,13 @@ begin
|
||||
begin
|
||||
// give a hint
|
||||
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;
|
||||
fpkMethod:
|
||||
// method hides a non proc
|
||||
@ -4785,11 +4790,14 @@ begin
|
||||
begin
|
||||
// Delphi/FPC do not give a message when hiding a non virtual method
|
||||
// -> 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
|
||||
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
|
||||
// hidden method has implementation, but no statements -> useless
|
||||
// -> do not give a hint for hiding this useless method
|
||||
@ -4797,13 +4805,13 @@ begin
|
||||
else if (Proc is TPasConstructor)
|
||||
and (Data^.Proc.ClassType=Proc.ClassType) then
|
||||
// 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
|
||||
begin
|
||||
//writeln('TPasResolver.OnFindProc Proc=',Proc.PathName,' Data^.Proc=',Data^.Proc.PathName,' ',Proc.Visibility);
|
||||
LogMsg(20171118214523,mtHint,
|
||||
nFunctionHidesIdentifier_NonVirtualMethod,sFunctionHidesIdentifier,
|
||||
[GetElementSourcePosStr(Proc)],Data^.Proc.ProcType);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Abort:=true;
|
||||
|
@ -9358,21 +9358,38 @@ end;
|
||||
|
||||
procedure TTestResolver.TestClass_NoHintMethodHidesPrivateMethod;
|
||||
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([
|
||||
'uses unit2;',
|
||||
'type',
|
||||
' TObject = class',
|
||||
' TAnimal = class',
|
||||
' strict private',
|
||||
' procedure DoIt(p: pointer);',
|
||||
' procedure Fly(p: pointer);',
|
||||
' end;',
|
||||
' TBird = class',
|
||||
' TBird = class(TAnimal)',
|
||||
' procedure DoIt(i: longint);',
|
||||
' procedure Fly(b: boolean);',
|
||||
' end;',
|
||||
'procedure TObject.DoIt(p: pointer);',
|
||||
'procedure TAnimal.Fly(p: pointer);',
|
||||
'begin',
|
||||
' if p=nil then ;',
|
||||
'end;',
|
||||
'procedure TBird.DoIt(i: longint); begin end;',
|
||||
'procedure TBird.Fly(b: boolean); begin end;',
|
||||
'var b: TBird;',
|
||||
'begin',
|
||||
' b.DoIt(3);']);
|
||||
|
Loading…
Reference in New Issue
Block a user