diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index f993087abe611..a6270579b6a3c 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -4970,6 +4970,13 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) { if (!isa(dc)) return; + // If this is not bound to any decls at this point, this extension is in + // 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); diff --git a/validation-test/IDE/crashers_2_fixed/sr9001.swift b/validation-test/IDE/crashers_2_fixed/sr9001.swift new file mode 100644 index 0000000000000..a35b02ada948f --- /dev/null +++ b/validation-test/IDE/crashers_2_fixed/sr9001.swift @@ -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 { +} + +protocol MyProto { + associatedtype Assoc + func foo(x: Assoc) -> Assoc +} + +#if false +extension MyStruct { + #^COMPLETE_1^# +} + +extension MyStruct: MyProto { + #^COMPLETE_2^# +} +#endif