Skip to content

[3.1][CodeComplete] Don't emit 'override' in protocol extension #7160

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
8 changes: 6 additions & 2 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4139,8 +4139,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {

// FIXME: if we're missing 'override', but have the decl introducer we
// should delete it and re-add both in the correct order.
bool missingOverride = Reason == DeclVisibilityKind::MemberOfSuper &&
!hasOverride;
bool missingOverride =
!hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
!CurrDeclContext->getAsProtocolOrProtocolExtensionContext();
if (!hasDeclIntroducer && missingOverride)
Builder.addOverrideKeyword();

Expand Down Expand Up @@ -4192,6 +4193,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
addAccessControl(CD, Builder);

if (!hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
!CurrDeclContext->getAsProtocolOrProtocolExtensionContext() &&
CD->isDesignatedInit() && !CD->isRequired())
Builder.addOverrideKeyword();

Expand Down Expand Up @@ -4333,6 +4335,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
void getOverrideCompletions(SourceLoc Loc) {
if (!CurrDeclContext->getAsNominalTypeOrNominalTypeExtensionContext())
return;
if (isa<ProtocolDecl>(CurrDeclContext))
return;

Type CurrTy = CurrDeclContext->getDeclaredTypeInContext();
if (CurrTy && !CurrTy->is<ErrorType>()) {
Expand Down
24 changes: 24 additions & 0 deletions test/IDE/complete_override.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
// RUN: %FileCheck %s -check-prefix=CLASS_PEI_PE < %t.txt
// RUN: %FileCheck %s -check-prefix=WITH_PEI < %t.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA -code-completion-keywords=false > %t.txt
// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA < %t.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA_EXT -code-completion-keywords=false > %t.txt
// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA_EXT < %t.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_NOMINAL -code-completion-keywords=false > %t.txt
// RUN: %FileCheck %s -check-prefix=NESTED_NOMINAL < %t.txt

Expand Down Expand Up @@ -362,6 +368,24 @@ class TestClass_PEI_PE : ProtocolEImpl, ProtocolE {
}
// CLASS_PEI_PE: Begin completions, 4 items

protocol TestProtocol_PA : ProtocolA {
#^PROTOCOL_PA^#
}
// PROTOCOL_PA: found code completion token
// PROTOCOL_PA-NOT: Begin completions

extension TestProtocol_PA {
#^PROTOCOL_PA_EXT^#
}

// PROTOCOL_PA_EXT: Begin completions
// PROTOCOL_PA_EXT-DAG: Decl[Constructor]/Super: init(fromProtocolA: Int) {|}; name=init(fromProtocolA: Int)
// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super: func protoAFunc() {|}; name=protoAFunc()
// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super: func protoAFuncOptional() {|}; name=protoAFuncOptional()
// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super: var protoAVarRW: Int; name=protoAVarRW: Int
// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super: var protoAVarRO: Int; name=protoAVarRO: Int
// PROTOCOL_PA_EXT: End completions

class OuterNominal : ProtocolA {
class Inner {
#^NESTED_NOMINAL^#
Expand Down