Skip to content

Commit e170dee

Browse files
rintaroakyrtzi
authored andcommitted
[AST] Fix a crash in UnqualifiedLookup
Add null type check for `Self` type in `UnqualifiedLookup`. It seems this doesn't happen in normal compilation. But when code-completion happens in inactive conditional compilation block, since surrounding context hasn't been typechecked, `Self` type can be null. rdar://problem/41234606
1 parent 9d01b59 commit e170dee

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
816816
return;
817817
}
818818

819-
if (BaseDC && !ExtendedType->hasError()) {
819+
if (BaseDC && ExtendedType && !ExtendedType->hasError()) {
820820
NLOptions options = baseNLOptions;
821821
if (isCascadingUse.getValue())
822822
options |= NL_KnownCascadingDependency;

test/IDE/complete_crashes.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,15 @@ func test_42452085(any: Any, obj: cls_42452085?) throws {
343343
_ = try obj?.canThrow() #^RDAR_42452085_3^#
344344
}
345345
// RDAR_42452085: found code completion token
346+
347+
// rdar://problem/41234606
348+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_41234606 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_41234606
349+
#if false
350+
extension Foo {
351+
func foo<T: Collection #^RDAR_41234606^#>(x: T) {}
352+
}
353+
#endif
354+
// RDAR_41234606: Begin completion
355+
// RDAR_41234606-DAG: Decl[AssociatedType]/Super: .Element; name=Element
356+
// RDAR_41234606-DAG: Decl[AssociatedType]/Super: .Iterator; name=Iterator
357+
// RDAR_41234606: End completions

0 commit comments

Comments
 (0)