Skip to content

[CodeCompletion] Don't try to resolve generic env for extension in inactive block #20015

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
merged 1 commit into from
Oct 27, 2018
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
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4970,6 +4970,13 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
if (!isa<SourceFile>(dc))
return;

// If this is not bound to any decls at this point, this extension is in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to before the validateDecl() call

// inactive coditional compilation block. It's not safe to typecheck this
// extension. This happens if code completion is triggered in inactive
// conditional complation block.
if (!ext->alreadyBoundToNominal())
return;

// Validate the nominal type declaration being extended.
validateDecl(nominal);

Expand Down
20 changes: 20 additions & 0 deletions validation-test/IDE/crashers_2_fixed/sr9001.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_1 -source-filename=%s
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_2 -source-filename=%s

struct MyStruct<T> {
}

protocol MyProto {
associatedtype Assoc
func foo(x: Assoc) -> Assoc
}

#if false
extension MyStruct {
#^COMPLETE_1^#
}

extension MyStruct: MyProto {
#^COMPLETE_2^#
}
#endif