Skip to content

Commit ae415b2

Browse files
committed
When followed by an 'override' or CC token inside a class, treat 'class' as a modifier rather than an introducer.
1 parent ecfce56 commit ae415b2

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,10 +4680,11 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
46804680
break;
46814681

46824682
case CompletionKind::NominalMemberBeginning: {
4683-
bool HasDeclIntroducer = llvm::find_if(ParsedKeywords, [](const StringRef kw) {
4683+
bool HasDeclIntroducer = llvm::find_if(ParsedKeywords,
4684+
[this](const StringRef kw) {
46844685
return llvm::StringSwitch<bool>(kw)
46854686
.Case("associatedtype", true)
4686-
.Case("class", true)
4687+
.Case("class", !CurDeclContext || !isa<ClassDecl>(CurDeclContext))
46874688
.Case("deinit", true)
46884689
.Case("enum", true)
46894690
.Case("extension", true)

lib/Parse/ParseDecl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,9 +2281,18 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
22812281
{
22822282
BacktrackingScope Scope(*this);
22832283
consumeToken(tok::kw_class);
2284-
if (!isStartOfDecl())
2284+
// When followed by an 'override' or CC token inside a class,
2285+
// treat 'class' as a modifier; in the case of a following CC
2286+
// token, we cannot be sure there is no intention to override
2287+
// or witness something static.
2288+
if (isStartOfDecl() || (isa<ClassDecl>(CurDeclContext) &&
2289+
(Tok.is(tok::code_complete) ||
2290+
Tok.getRawText().equals("override")))) {
2291+
/* We're OK */
2292+
} else {
22852293
// This 'class' is a real ClassDecl introducer.
22862294
break;
2295+
}
22872296
}
22882297
if (StaticLoc.isValid()) {
22892298
diagnose(Tok, diag::decl_already_static,

test/IDE/complete_override.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=MODIFIER22 -code-completion-keywords=false | %FileCheck %s -check-prefix=MODIFIER22
141141
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=MODIFIER23 -code-completion-keywords=false | %FileCheck %s -check-prefix=MODIFIER23
142142
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=MODIFIER24 -code-completion-keywords=false | %FileCheck %s -check-prefix=MODIFIER24
143+
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=MODIFIER25 -code-completion-keywords=false | %FileCheck %s -check-prefix=MODIFIER23
144+
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=MODIFIER26 -code-completion-keywords=false | %FileCheck %s -check-prefix=MODIFIER24
143145

144146
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=PROTOINIT_NORM -code-completion-keywords=false | %FileCheck %s -check-prefix=PROTOINIT_NORM
145147
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=PROTOINIT_FINAL -code-completion-keywords=false | %FileCheck %s -check-prefix=PROTOINIT_FINAL
@@ -689,6 +691,14 @@ class Override23 : OverrideBase, OverrideP {
689691
class Override24 : OverrideBase, OverrideP {
690692
override static #^MODIFIER24^#
691693
}
694+
class Override25 : OverrideBase, OverrideP {
695+
class #^MODIFIER25^#
696+
// Same as MODIFIER23
697+
}
698+
class Override26 : OverrideBase, OverrideP {
699+
class override #^MODIFIER26^#
700+
// Same as MODIFIER24
701+
}
692702

693703
// MODIFIER1: Begin completions, 9 items
694704
// MODIFIER1-DAG: Decl[Constructor]/Super: required init(p: Int) {|}; name=required init(p: Int)

0 commit comments

Comments
 (0)