From c36f3fe0a5e4c467032817c2bdbf5470e5d8d7e2 Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 10 Mar 2025 08:52:23 +0100 Subject: [PATCH] codetools: fixed TFindDeclarationTool.FindOverridenMethodDecl searching next ancestor --- components/codetools/finddeclarationtool.pas | 15 +++++++++------ components/codetools/tests/testrefactoring.pas | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index a175588a48..775c25afa7 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -12314,14 +12314,14 @@ begin end else if Node.Desc in AllSimpleIdentifierDefinitions then begin if CompareIdentifiers(@CurTool.Src[Node.StartPos],Identifier)=0 then - exit; + exit; // ancestor has field or constant with same name -> stop end else if Node.Desc=ctnProperty then begin CurIdentifier:=GetPropertyNameIdentifier(Node); if CompareIdentifiers(CurIdentifier,Identifier)=0 then - exit; + exit; // ancestor has property with same name -> stop end else if Node.Desc=ctnProcedure then begin CurIdentifier:=CurTool.GetProcNameIdentifier(Node); - //debugln([' TFindDeclarationTool.FindOverridenMethodDecl PROC "',CurIdentifier,'"']); + //debugln([' TFindDeclarationTool.FindOverridenMethodDecl PROC "',GetIdentifier(CurIdentifier),'"']); if CompareIdentifiers(CurIdentifier,Identifier)=0 then begin // found ancestor method with same name {$IFDEF VerboseFindRefMethodOverrides} @@ -12367,7 +12367,7 @@ begin end else if Node.Desc=ctnGenericType then begin if (Node.FirstChild<>nil) and (CompareIdentifiers(@Src[Node.FirstChild.StartPos],Identifier)=0) then - exit; + exit; // ancestor has a generic type with same name -> stop end; // next if Node.PriorBrother<>nil then @@ -12375,12 +12375,15 @@ begin else begin repeat Node:=Node.Parent; - if Node=ClassNode then exit; + if Node=ClassNode then begin + Node:=nil; + break; + end; until Node.PriorBrother<>nil; + if Node=nil then break; Node:=Node.PriorBrother; end; end; - end; finally diff --git a/components/codetools/tests/testrefactoring.pas b/components/codetools/tests/testrefactoring.pas index a57ca3778d..a49ac40d0a 100644 --- a/components/codetools/tests/testrefactoring.pas +++ b/components/codetools/tests/testrefactoring.pas @@ -805,7 +805,9 @@ begin ' TAnimal = class', ' procedure Fly{#Rename}; virtual;', ' end;', - ' TBird = class(TAnimal)', + ' TFlying = class(TAnimal)', + ' end;', + ' TBird = class(TFlying)', ' procedure Eat;', ' procedure Fly; override;', ' end;', @@ -840,7 +842,9 @@ begin ' TAnimal = class', ' procedure Run{#Rename}; virtual;', ' end;', - ' TBird = class(TAnimal)', + ' TFlying = class(TAnimal)', + ' end;', + ' TBird = class(TFlying)', ' procedure Eat;', ' procedure Run; override;', ' end;',