Skip to content

[4.0][index] Add missing parameter and return type references in subscript declarations #10537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,6 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (!report(VD))
return false;
if (auto *SD = dyn_cast<SubscriptDecl>(VD)) {
// Avoid indexing the indices, only walk the getter/setter.
if (SD->getGetter())
if (SourceEntityWalker::walk(cast<Decl>(SD->getGetter())))
return false;
if (SD->getSetter())
if (SourceEntityWalker::walk(cast<Decl>(SD->getSetter())))
return false;
if (SD->hasAddressors()) {
if (auto FD = SD->getAddressor())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
if (auto FD = SD->getMutableAddressor())
SourceEntityWalker::walk(cast<Decl>(FD));
}
walkToDeclPost(D);
return false; // already walked what we needed.
}
}
if (auto *ED = dyn_cast<ExtensionDecl>(D))
return reportExtension(ED);
Expand Down Expand Up @@ -885,12 +866,13 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
bool IndexSwiftASTWalker::report(ValueDecl *D) {
if (startEntityDecl(D)) {
// Pass accessors.
if (auto VarD = dyn_cast<VarDecl>(D)) {
if (auto StoreD = dyn_cast<AbstractStorageDecl>(D)) {
auto isNullOrImplicit = [](const Decl *D) -> bool {
return !D || D->isImplicit();
};
if (isNullOrImplicit(VarD->getGetter()) &&
isNullOrImplicit(VarD->getSetter())) {
if (isa<VarDecl>(D) && isNullOrImplicit(StoreD->getGetter()) &&
isNullOrImplicit(StoreD->getSetter())) {
auto VarD = cast<VarDecl>(D);
// No actual getter or setter, pass 'pseudo' accessors.
// We create accessor entities so we can implement the functionality
// of libclang, which reports implicit method property accessor
Expand All @@ -903,31 +885,31 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
if (!reportPseudoSetterDecl(VarD))
return false;
} else {
if (auto FD = VarD->getGetter())
if (auto FD = StoreD->getGetter())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
if (auto FD = VarD->getSetter())
if (auto FD = StoreD->getSetter())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
}
if (VarD->hasObservers()) {
if (auto FD = VarD->getWillSetFunc())
if (StoreD->hasObservers()) {
if (auto FD = StoreD->getWillSetFunc())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
if (auto FD = VarD->getDidSetFunc())
if (auto FD = StoreD->getDidSetFunc())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
}
if (VarD->hasAddressors()) {
if (auto FD = VarD->getAddressor())
if (StoreD->hasAddressors()) {
if (auto FD = StoreD->getAddressor())
SourceEntityWalker::walk(cast<Decl>(FD));
if (Cancelled)
return false;
if (auto FD = VarD->getMutableAddressor())
if (auto FD = StoreD->getMutableAddressor())
SourceEntityWalker::walk(cast<Decl>(FD));
}
} else if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
Expand Down
3 changes: 3 additions & 0 deletions test/Index/kinds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct AStruct {
return base
}
}
// CHECK: [[@LINE-20]]:13 | param/Swift | index | {{.*}} | Def,RelChild | rel: 1
// CHECK: [[@LINE-21]]:20 | struct/Swift | Int | {{.*}} | Ref | rel: 0
// CHECK: [[@LINE-22]]:28 | struct/Swift | Int | {{.*}} | Ref | rel: 0
}

// Class
Expand Down