Skip to content

Commit 2c5f965

Browse files
committed
Fix crash when module in selector doesn’t exist
# Conflicts: # lib/AST/UnqualifiedLookup.cpp
1 parent ddbcccd commit 2c5f965

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
@@ -381,6 +381,8 @@ void UnqualifiedLookupFactory::setAsideUnavailableResults(
381381
}
382382

383383
void UnqualifiedLookupFactory::addImportedResults(const DeclContext *const dc) {
384+
assert(dc);
385+
384386
using namespace namelookup;
385387
SmallVector<ValueDecl *, 8> CurModuleResults;
386388
auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
@@ -391,6 +393,10 @@ void UnqualifiedLookupFactory::addImportedResults(const DeclContext *const dc) {
391393
// We'd need a new ResolutionKind.
392394
moduleToLookIn =
393395
dc->getASTContext().getLoadedModule(Name.getModuleSelector());
396+
397+
// If we didn't find the module, it obviously can't have any results.
398+
if (!moduleToLookIn)
399+
return;
394400

395401
auto nlOptions = NL_UnqualifiedDefault;
396402
if (options.contains(Flags::IncludeUsableFromInline))

test/NameLookup/module_selector.swift

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

0 commit comments

Comments
 (0)