mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 07:46:00 +02:00
fcl-passrc: resolver: check duplicate class forwards
git-svn-id: trunk@38224 -
This commit is contained in:
parent
032c8f99a6
commit
2ae54c3c00
@ -5191,9 +5191,24 @@ var
|
|||||||
aModifier: String;
|
aModifier: String;
|
||||||
IsSealed: Boolean;
|
IsSealed: Boolean;
|
||||||
CanonicalSelf: TPasClassOfType;
|
CanonicalSelf: TPasClassOfType;
|
||||||
|
ParentDecls: TPasDeclarations;
|
||||||
|
Decl: TPasElement;
|
||||||
begin
|
begin
|
||||||
if aClass.IsForward then
|
if aClass.IsForward then
|
||||||
|
begin
|
||||||
|
// check for duplicate forwards
|
||||||
|
ParentDecls:=aClass.Parent as TPasDeclarations;
|
||||||
|
for i:=0 to ParentDecls.Declarations.Count-1 do
|
||||||
|
begin
|
||||||
|
Decl:=TPasElement(ParentDecls.Declarations[i]);
|
||||||
|
if (CompareText(Decl.Name,aClass.Name)=0)
|
||||||
|
and (Decl<>aClass) then
|
||||||
|
RaiseMsg(20180212144132,nDuplicateIdentifier,sDuplicateIdentifier,
|
||||||
|
[Decl.Name,GetElementSourcePosStr(Decl)],aClass);
|
||||||
|
end;
|
||||||
exit;
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
if aClass.ObjKind<>okClass then
|
if aClass.ObjKind<>okClass then
|
||||||
begin
|
begin
|
||||||
if (aClass.ObjKind=okInterface)
|
if (aClass.ObjKind=okInterface)
|
||||||
@ -7103,7 +7118,7 @@ begin
|
|||||||
if not (TopScope is TPasSectionScope) then
|
if not (TopScope is TPasSectionScope) then
|
||||||
RaiseNotYetImplemented(20171225110934,El,'nested classes');
|
RaiseNotYetImplemented(20171225110934,El,'nested classes');
|
||||||
|
|
||||||
Duplicate:=TPasIdentifierScope(TopScope).FindIdentifier(El.Name);
|
Duplicate:=TPasIdentifierScope(TopScope).FindLocalIdentifier(El.Name);
|
||||||
//if Duplicate<>nil then
|
//if Duplicate<>nil then
|
||||||
//writeln(' Duplicate=',GetObjName(Duplicate.Element),' ',ord(Duplicate.Kind));
|
//writeln(' Duplicate=',GetObjName(Duplicate.Element),' ',ord(Duplicate.Kind));
|
||||||
|
|
||||||
|
@ -427,6 +427,7 @@ type
|
|||||||
Procedure TestClassForward;
|
Procedure TestClassForward;
|
||||||
Procedure TestClassForwardAsAncestorFail;
|
Procedure TestClassForwardAsAncestorFail;
|
||||||
Procedure TestClassForwardNotResolved;
|
Procedure TestClassForwardNotResolved;
|
||||||
|
Procedure TestClassForwardDuplicateFail;
|
||||||
Procedure TestClass_Method;
|
Procedure TestClass_Method;
|
||||||
Procedure TestClass_ConstructorMissingDotFail;
|
Procedure TestClass_ConstructorMissingDotFail;
|
||||||
Procedure TestClass_MethodImplDuplicateFail;
|
Procedure TestClass_MethodImplDuplicateFail;
|
||||||
@ -6518,6 +6519,19 @@ begin
|
|||||||
nForwardTypeNotResolved);
|
nForwardTypeNotResolved);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestClassForwardDuplicateFail;
|
||||||
|
begin
|
||||||
|
StartProgram(false);
|
||||||
|
Add([
|
||||||
|
'type',
|
||||||
|
' TObject = class;',
|
||||||
|
' TObject = class;',
|
||||||
|
' TObject = class',
|
||||||
|
' end;',
|
||||||
|
'begin']);
|
||||||
|
CheckResolverException('Duplicate identifier "TObject" at afile.pp(3,10)',nDuplicateIdentifier);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestResolver.TestClass_Method;
|
procedure TTestResolver.TestClass_Method;
|
||||||
begin
|
begin
|
||||||
StartProgram(false);
|
StartProgram(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user