Skip to content

Commit 07172f4

Browse files
committed
[CodeCompletion] Don't try to resolve generic env for extension in inactive block
Fixes code-completion crash in validateExtension(). When code completion happens, it tries to validate decl contexts. If it's in an extension in inactivec conditional block, the extension haven't been bound to nominal type. That used to cause crash because its GenericParams hasn't been set. rdar://problem/45275782 https://bugs.swift.org/browse/SR-9001
1 parent c2dad28 commit 07172f4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,6 +4970,13 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
49704970
if (!isa<SourceFile>(dc))
49714971
return;
49724972

4973+
// If this is not bound to any decls at this point, this extension is in
4974+
// inactive coditional compilation block. It's not safe to typecheck this
4975+
// extension. This happens if code completion is triggered in inactive
4976+
// conditional complation block.
4977+
if (!ext->alreadyBoundToNominal())
4978+
return;
4979+
49734980
// Validate the nominal type declaration being extended.
49744981
validateDecl(nominal);
49754982

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_1 -source-filename=%s
2+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_2 -source-filename=%s
3+
4+
struct MyStruct<T> {
5+
}
6+
7+
protocol MyProto {
8+
associatedtype Assoc
9+
func foo(x: Assoc) -> Assoc
10+
}
11+
12+
#if false
13+
extension MyStruct {
14+
#^COMPLETE_1^#
15+
}
16+
17+
extension MyStruct: MyProto {
18+
#^COMPLETE_2^#
19+
}
20+
#endif

0 commit comments

Comments
 (0)