mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 18:09:27 +02:00
fcl-passrc: no hint on hiding inherited constructor, fixed Result:=inherited;
git-svn-id: trunk@40204 -
This commit is contained in:
parent
1bd8e903d7
commit
c160d93750
@ -4373,6 +4373,9 @@ begin
|
||||
// hidden method has implementation, but no statements -> useless
|
||||
// -> do not give a hint for hiding this useless method
|
||||
// Note: if this happens in the same unit, the body was not yet parsed
|
||||
else if (Proc is TPasConstructor)
|
||||
and (Data^.Proc.ClassType=Proc.ClassType) then
|
||||
// do not give a hint for hiding a constructor
|
||||
else
|
||||
LogMsg(20171118214523,mtHint,
|
||||
nFunctionHidesIdentifier_NonVirtualMethod,sFunctionHidesIdentifier,
|
||||
@ -19463,6 +19466,50 @@ procedure TPasResolver.ComputeElement(El: TPasElement; out
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure ComputeInherited(Expr: TInheritedExpr);
|
||||
var
|
||||
Ref: TResolvedReference;
|
||||
Proc: TPasProcedure;
|
||||
TypeEl: TPasProcedureType;
|
||||
aClass: TPasClassType;
|
||||
HasName: Boolean;
|
||||
begin
|
||||
// "inherited;"
|
||||
Ref:=TResolvedReference(El.CustomData);
|
||||
Proc:=NoNil(Ref.Declaration) as TPasProcedure;
|
||||
TypeEl:=TPasProcedure(Proc).ProcType;
|
||||
SetResolverIdentifier(ResolvedEl,btProc,Proc,
|
||||
TypeEl,TypeEl,[rrfCanBeStatement]);
|
||||
HasName:=(El.Parent.ClassType=TBinaryExpr)
|
||||
and (TBinaryExpr(El.Parent).OpCode=eopNone); // true if 'inherited Proc;'
|
||||
if HasName or (rcNoImplicitProc in Flags) then
|
||||
exit;
|
||||
|
||||
// inherited; -> implicit call possible
|
||||
if Proc is TPasFunction then
|
||||
begin
|
||||
// function => return result
|
||||
ComputeElement(TPasFunction(Proc).FuncType.ResultEl,
|
||||
ResolvedEl,Flags+[rcType],StartEl);
|
||||
Exclude(ResolvedEl.Flags,rrfWritable);
|
||||
end
|
||||
else if (Proc.ClassType=TPasConstructor)
|
||||
and (rrfNewInstance in Ref.Flags) then
|
||||
begin
|
||||
// new instance constructor -> return value of type class
|
||||
aClass:=GetReference_NewInstanceClass(Ref);
|
||||
SetResolverValueExpr(ResolvedEl,btContext,aClass,aClass,Expr,[rrfReadable]);
|
||||
end
|
||||
else if ParentNeedsExprResult(Expr) then
|
||||
begin
|
||||
// a procedure
|
||||
exit;
|
||||
end;
|
||||
if rcSetReferenceFlags in Flags then
|
||||
Include(Ref.Flags,rrfImplicitCallWithoutParams);
|
||||
Include(ResolvedEl.Flags,rrfCanBeStatement);
|
||||
end;
|
||||
|
||||
var
|
||||
DeclEl: TPasElement;
|
||||
ElClass: TClass;
|
||||
@ -19622,13 +19669,7 @@ begin
|
||||
begin
|
||||
// writeln('TPasResolver.ComputeElement TInheritedExpr El.CustomData=',GetObjName(El.CustomData));
|
||||
if El.CustomData is TResolvedReference then
|
||||
begin
|
||||
// "inherited;"
|
||||
DeclEl:=NoNil(TResolvedReference(El.CustomData).Declaration) as TPasProcedure;
|
||||
TypeEl:=TPasProcedure(DeclEl).ProcType;
|
||||
SetResolverIdentifier(ResolvedEl,btProc,DeclEl,
|
||||
TypeEl,TypeEl,[rrfCanBeStatement]);
|
||||
end
|
||||
ComputeInherited(TInheritedExpr(El))
|
||||
else
|
||||
// no ancestor proc
|
||||
SetResolverIdentifier(ResolvedEl,btBuiltInProc,nil,nil,nil,[rrfCanBeStatement]);
|
||||
|
@ -881,7 +881,7 @@ begin
|
||||
Result.Element:=El;
|
||||
FUsedElements.Add(Result);
|
||||
{$IFDEF VerbosePasAnalyzer}
|
||||
writeln('TPasAnalyzer.Add END ',GetElModName(El),' Success=',PAElementExists(El),' ',{$Ifdef pas2js}El.PasElementId{$else}ptruint(pointer(El)){$endif});
|
||||
writeln('TPasAnalyzer.Add END ',GetElModName(El),' Success=',PAElementExists(El),' '{$Ifdef pas2js},El.PasElementId{$endif});
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user