Skip to content

Commit 1e8fe05

Browse files
committed
Fix crash when module in selector doesn’t exist
1 parent bb39cef commit 1e8fe05

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ void UnqualifiedLookupFactory::setAsideUnavailableResults(
472472
}
473473

474474
void UnqualifiedLookupFactory::addImportedResults(const DeclContext *const dc) {
475+
assert(dc);
476+
475477
using namespace namelookup;
476478
SmallVector<ValueDecl *, 8> CurModuleResults;
477479
auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
@@ -483,6 +485,10 @@ void UnqualifiedLookupFactory::addImportedResults(const DeclContext *const dc) {
483485
// We'd need a new ResolutionKind.
484486
moduleToLookIn =
485487
dc->getASTContext().getLoadedModule(Name.getModuleSelector());
488+
489+
// If we didn't find the module, it obviously can't have any results.
490+
if (!moduleToLookIn)
491+
return;
486492

487493
auto nlOptions = NL_UnqualifiedDefault;
488494
if (options.contains(Flags::IncludeUsableFromInline))

test/NameLookup/module_selector.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,19 @@ precedencegroup main::PG1 {
449449
higherThan: Swift::AdditionPrecedence
450450
// expected-error@-1 {{precedence group specifier cannot be qualified with module selector}}
451451
}
452+
453+
func badModuleNames() {
454+
NonexistentModule::print()
455+
// expected-error@-1 {{declaration 'print' is not imported through module 'NonexistentModule'}}
456+
// expected-note@-2 {{did you mean module 'Swift'?}} {{3-20=Swift}}
457+
// FIXME redundant: expected-note@-3 {{did you mean module 'Swift'?}}
458+
459+
_ = "foo".NonexistentModule::count
460+
// FIXME improve: expected-error@-1 {{value of type 'String' has no member 'NonexistentModule::count'}}
461+
462+
let x: NonexistentModule::MyType = NonexistentModule::MyType()
463+
// expected-error@-1 {{use of undeclared type 'NonexistentModule::MyType'}}
464+
465+
let y: A.NonexistentModule::MyChildType = fatalError()
466+
// expected-error@-1 {{'NonexistentModule::MyChildType' is not a member type of 'A'}}
467+
}

0 commit comments

Comments
 (0)