Skip to content

[5.9] Add a target nil check #65110

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
Apr 13, 2023
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
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(void)ID->getDecls();

auto target = ID->getModule();
if (!getASTContext().LangOpts.PackageName.empty() &&
if (target && // module would be nil if loading fails
!getASTContext().LangOpts.PackageName.empty() &&
getASTContext().LangOpts.PackageName == target->getPackageName().str() &&
!target->isNonSwiftModule() && // target is a Swift module
target->isNonUserModule()) { // target module is in distributed SDK
Expand Down
6 changes: 4 additions & 2 deletions test/Sema/import_package_module_from_sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

// RUN: %target-swift-frontend -typecheck -verify %t/Client2.swift -package-name libPkg -I %t

// RUN: rm %t/LibLocal.swiftmodule
// RUN: not %target-swift-frontend -typecheck %t/Client2.swift -package-name libPkg -I %t 2>&1 | %FileCheck %s
// CHECK: error: no such module 'LibLocal'

//--- Lib.swift
package func log(level: Int) {}

Expand All @@ -37,5 +41,3 @@ import LibLocal
func someFunc() {
log(level: 1)
}