Skip to content

Commit 812d156

Browse files
committed
[CodeCompletion] Don't look through non-type contexts in override
We don't actually want to skip non-type contexts here, since we should only be showing override completions in the type context itself. This was pretty obscure to hit in practice, but I noticed it while fixing the crasher.
1 parent 81eb2fa commit 812d156

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,11 +3728,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
37283728
NameOffset = Printer.NameOffset.getValue();
37293729
}
37303730

3731-
auto typeContext = CurrDeclContext->getInnermostTypeContext();
3732-
assert(typeContext &&
3733-
typeContext->getAsGenericTypeOrGenericTypeExtensionContext());
3731+
assert(CurrDeclContext->getAsGenericTypeOrGenericTypeExtensionContext());
37343732
Accessibility AccessibilityOfContext =
3735-
typeContext->getAsGenericTypeOrGenericTypeExtensionContext()
3733+
CurrDeclContext->getAsGenericTypeOrGenericTypeExtensionContext()
37363734
->getFormalAccess();
37373735

37383736
bool missingDeclIntroducer = !hasVarIntroducer && !hasFuncIntroducer;
@@ -3865,15 +3863,13 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
38653863
}
38663864

38673865
void getOverrideCompletions(SourceLoc Loc) {
3868-
if (auto TypeContext = CurrDeclContext->getInnermostTypeContext()){
3869-
if (!TypeContext->getAsGenericTypeOrGenericTypeExtensionContext())
3870-
return;
3866+
if (!CurrDeclContext->getAsGenericTypeOrGenericTypeExtensionContext())
3867+
return;
38713868

3872-
if (Type CurrTy = TypeContext->getDeclaredTypeInContext()) {
3873-
lookupVisibleMemberDecls(*this, CurrTy, CurrDeclContext,
3874-
TypeResolver.get());
3875-
addDesignatedInitializers(CurrTy);
3876-
}
3869+
if (Type CurrTy = CurrDeclContext->getDeclaredTypeInContext()) {
3870+
lookupVisibleMemberDecls(*this, CurrTy, CurrDeclContext,
3871+
TypeResolver.get());
3872+
addDesignatedInitializers(CurrTy);
38773873
}
38783874
}
38793875
};

test/IDE/complete_override.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
// RUN: FileCheck %s -check-prefix=NESTED_NOMINAL < %t.txt
8383

8484
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_CLOSURE_1 -code-completion-keywords=false | FileCheck %s -check-prefix=NESTED_CLOSURE_1
85+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_CLOSURE_2 -code-completion-keywords=false | FileCheck %s -check-prefix=NESTED_CLOSURE_2
8586

8687
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OMIT_KEYWORD1 -code-completion-keywords=false > %t.txt
8788
// RUN: FileCheck %s -check-prefix=OMIT_KEYWORD1< %t.txt
@@ -364,6 +365,12 @@ class OuterNominal2: ProtocolA {
364365
// NESTED_CLOSURE_1-NOT: Decl{{.*}}/Super
365366
// NESTED_CLOSURE_1-NOT: {|}
366367

368+
class OuterNominal3: ProtocolA {
369+
var f = { static #^NESTED_CLOSURE_2^# }()
370+
}
371+
// NESTED_CLOSURE_2-NOT: Decl{{.*}}/Super
372+
// NESTED_CLOSURE_2-NOT: {|}
373+
367374
class OmitKW1 : ProtocolA {
368375
override#^OMIT_KEYWORD1^#
369376
}

validation-test/IDE/crashers_fixed/009-swift-performdelayedparsing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
enum b:a{var f={static#^A^#
33
// FIXME: we shouldn't back the parser to the beginning of the line, it leads
44
// to ridiculous override completions like this.
5-
// CHECK: Decl[InstanceVar]/Super: var rawValue: Self.RawValue;
5+
// CHECK-NOT: Decl{{.*}}/Super

0 commit comments

Comments
 (0)