Skip to content

Commit 7edb90b

Browse files
Cirrasfourls
authored andcommitted
Fix name resolution failures around ancestors of enclosing types
1 parent 7bd1b21 commit 7edb90b

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
- False positives on enumerator property `Current` in `UnusedProperty`.
3838
- False positives on enums that are never referenced by name (but have used values) in `UnusedType`.
3939
- Name resolution failures in legacy initialization sections referencing the implementation section.
40+
- Name resolution failures whena accessing ancestors of enclosing types from nested type methods.
4041
- Incorrect file position calculation for multiline string tokens.
4142
- Analysis errors around `type of` type declarations.
4243

delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/Search.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ private Set<NameDeclaration> searchTypeScope(TypeScope scope) {
253253
private Set<NameDeclaration> searchEnclosingTypes(@Nullable DelphiScope scope) {
254254
Set<NameDeclaration> result = Collections.emptySet();
255255
if (scope != null) {
256-
TypeScope nextTypeScope = scope.getEnclosingScope(TypeScope.class);
257-
if (nextTypeScope != null) {
256+
TypeScope enclosingTypeScope = scope.getEnclosingScope(TypeScope.class);
257+
if (enclosingTypeScope != null) {
258258
if (TRACE) {
259-
LOG.info(" checking enclosing type scope {}", nextTypeScope);
259+
LOG.info(" checking enclosing type scope {}", enclosingTypeScope);
260260
}
261-
result = filterTypeScopeResults(nextTypeScope.findDeclaration(occurrence));
261+
result = searchTypeScope(enclosingTypeScope);
262262
if (result.isEmpty()) {
263-
return searchEnclosingTypes(nextTypeScope.getParent());
263+
return searchEnclosingTypes(enclosingTypeScope.getParent());
264264
}
265265
}
266266
}

delphi-frontend/src/test/java/au/com/integradev/delphi/executor/DelphiSymbolTableExecutorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void testNestedTypes() {
179179
execute("NestedTypes.pas");
180180
verifyUsages(7, 8, reference(20, 10), reference(21, 5));
181181
verifyUsages(8, 26, reference(23, 4), reference(24, 4));
182+
verifyUsages(29, 20, reference(46, 2));
182183
}
183184

184185
@Test

delphi-frontend/src/test/resources/au/com/integradev/delphi/symbol/NestedTypes.pas

+22
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,26 @@ procedure TFoo.TBaz.Test;
2424
B.DoStuff;
2525
end;
2626

27+
type
28+
TFlimFlam = class
29+
class procedure Flarp;
30+
end;
31+
32+
TFoo = class(TFlimFlam)
33+
type
34+
TBar = class
35+
procedure Baz;
36+
end;
37+
end;
38+
39+
class procedure TFlimFlam.Flarp;
40+
begin
41+
// do nothing
42+
end;
43+
44+
procedure TFoo.TBar.Baz;
45+
begin
46+
Flarp;
47+
end;
48+
2749
end.

0 commit comments

Comments
 (0)