Skip to content

[SourceKit] Mark overridable declarations as dynamic #74080

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
merged 1 commit into from
Jun 3, 2024
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
7 changes: 7 additions & 0 deletions lib/IDE/IDERequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ bool CursorInfoResolver::tryResolve(ValueDecl *D, TypeDecl *CtorTyRef,
IsDynamic = true;
ide::getReceiverType(BaseE, ReceiverTypes);
}
} else if (ExprStack.empty() && isDeclOverridable(D)) {
// We aren't in a call (otherwise we would have an expression stack wouldn't
// be empty), so we're at the declaration of an overridable declaration.
// Mark the declaration as dynamic so that jump-to-definition can offer to
// jump to any declaration that overrides this declaration.
IsDynamic = true;
ReceiverTypes.push_back(D->getDeclContext()->getSelfNominalTypeDecl());
}

if (Data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
protocol MyProto {
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s | %FileCheck %s
func foo()
}

// CHECK: DYNAMIC
// CHECK: RECEIVERS BEGIN
// CHECK: s:41cursor_of_protocol_requirement_is_dynamic7MyProtoP
// CHECK: RECEIVERS END

class ClassA: MyProto {
func foo() {}
}

class ClassB: MyProto {
func foo() {}
}