Skip to content

Commit ffbe663

Browse files
authored
Merge pull request #20015 from rintaro/ide-completion-rdar45275782
[CodeCompletion] Don't try to resolve generic env for extension in inactive block
2 parents c3b806b + 07172f4 commit ffbe663

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
@@ -4989,6 +4989,13 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
49894989
if (!isa<SourceFile>(dc))
49904990
return;
49914991

4992+
// If this is not bound to any decls at this point, this extension is in
4993+
// inactive coditional compilation block. It's not safe to typecheck this
4994+
// extension. This happens if code completion is triggered in inactive
4995+
// conditional complation block.
4996+
if (!ext->alreadyBoundToNominal())
4997+
return;
4998+
49924999
// Validate the nominal type declaration being extended.
49935000
validateDecl(nominal);
49945001

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)