Skip to content

Commit 7765fd6

Browse files
authored
Merge pull request #75249 from hamishknight/sudo-override-6.0
[6.0] [Index] Record relations for pseudo accessors
2 parents 9331f13 + 35fd094 commit 7765fd6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/Index/Index.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,14 +1055,34 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
10551055
return {{line, col, inGeneratedBuffer}};
10561056
}
10571057

1058+
bool shouldIndexImplicitDecl(const ValueDecl *D, bool IsRef) const {
1059+
// We index implicit constructors.
1060+
if (isa<ConstructorDecl>(D))
1061+
return true;
1062+
1063+
// Allow references to implicit getter & setter AccessorDecls on
1064+
// non-implicit storage, these are "pseudo accessors".
1065+
if (auto *AD = dyn_cast<AccessorDecl>(D)) {
1066+
if (!IsRef)
1067+
return false;
1068+
1069+
auto Kind = AD->getAccessorKind();
1070+
if (Kind != AccessorKind::Get && Kind != AccessorKind::Set)
1071+
return false;
1072+
1073+
return shouldIndex(AD->getStorage(), IsRef);
1074+
}
1075+
return false;
1076+
}
1077+
10581078
bool shouldIndex(const ValueDecl *D, bool IsRef) const {
10591079
if (D->isImplicit() && isa<VarDecl>(D) && IsRef) {
10601080
// Bypass the implicit VarDecls introduced in CaseStmt bodies by using the
10611081
// canonical VarDecl for these checks instead.
10621082
D = cast<VarDecl>(D)->getCanonicalVarDecl();
10631083
}
10641084

1065-
if (D->isImplicit() && !isa<ConstructorDecl>(D))
1085+
if (D->isImplicit() && !shouldIndexImplicitDecl(D, IsRef))
10661086
return false;
10671087

10681088
// Do not handle non-public imported decls.

test/Index/roles.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,28 @@ func containerFunc() {
539539
// CHECK: [[@LINE-16]]:15 | function/acc-get/Swift | getter:y | {{.*}} | Ref,Call,Impl,RelCall,RelCont | rel: 1
540540
// CHECK-NEXT: RelCall,RelCont | function/Swift | containerFunc()
541541
}
542+
543+
// rdar://131749546 - Make sure we record the override relation for the
544+
// pseudo accessor for 'x'.
545+
class BaseClass {
546+
var x = 0
547+
// CHECK: [[@LINE-1]]:7 | instance-property/Swift | x | s:14swift_ide_test9BaseClassC1xSivp | Def,RelChild | rel: 1
548+
// CHECK: [[@LINE-2]]:7 | instance-method/acc-get/Swift | getter:x | s:14swift_ide_test9BaseClassC1xSivg | Def,Dyn,Impl,RelChild,RelAcc | rel: 1
549+
// CHECK-NEXT: RelChild,RelAcc | instance-property/Swift | x | s:14swift_ide_test9BaseClassC1xSivp
550+
// CHECK: [[@LINE-4]]:7 | instance-method/acc-set/Swift | setter:x | s:14swift_ide_test9BaseClassC1xSivs | Def,Dyn,Impl,RelChild,RelAcc | rel: 1
551+
// CHECK-NEXT: RelChild,RelAcc | instance-property/Swift | x | s:14swift_ide_test9BaseClassC1xSivp
552+
}
553+
class Subclass: BaseClass {
554+
override var x: Int {
555+
// CHECK: [[@LINE-1]]:16 | instance-property/Swift | x | s:14swift_ide_test8SubclassC1xSivp | Def,RelChild,RelOver | rel: 2
556+
// CHECK-NEXT: RelOver | instance-property/Swift | x | s:14swift_ide_test9BaseClassC1xSivp
557+
get { 0 }
558+
// CHECK: [[@LINE-1]]:5 | instance-method/acc-get/Swift | getter:x | s:14swift_ide_test8SubclassC1xSivg | Def,Dyn,RelChild,RelOver,RelAcc | rel: 2
559+
// CHECK-NEXT: RelOver | instance-method/acc-get/Swift | getter:x | s:14swift_ide_test9BaseClassC1xSivg
560+
// CHECK-NEXT: RelChild,RelAcc | instance-property/Swift | x | s:14swift_ide_test8SubclassC1xSivp
561+
set {}
562+
// CHECK: [[@LINE-1]]:5 | instance-method/acc-set/Swift | setter:x | s:14swift_ide_test8SubclassC1xSivs | Def,Dyn,RelChild,RelOver,RelAcc | rel: 2
563+
// CHECK-NEXT: RelOver | instance-method/acc-set/Swift | setter:x | s:14swift_ide_test9BaseClassC1xSivs
564+
// CHECK-NEXT: RelChild,RelAcc | instance-property/Swift | x | s:14swift_ide_test8SubclassC1xSivp
565+
}
566+
}

0 commit comments

Comments
 (0)