Skip to content

Commit c9bbbbf

Browse files
authored
Merge pull request #68773 from xymus/sourceloc-package-swiftinterface
[Sema] Add sourceloc to the error on importing a package module from swiftinterface
2 parents 197a4a3 + 291b09e commit c9bbbbf

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void UnboundImport::validateInterfaceWithPackageName(ModuleDecl *topLevelModule,
770770
if (!topLevelModule->getPackageName().empty() &&
771771
topLevelModule->getPackageName().str() == ctx.LangOpts.PackageName &&
772772
topLevelModule->isBuiltFromInterface()) {
773-
ctx.Diags.diagnose(SourceLoc(),
773+
ctx.Diags.diagnose(import.module.getModulePath().front().Loc,
774774
diag::in_package_module_not_compiled_from_source,
775775
topLevelModule->getBaseIdentifier(),
776776
ctx.LangOpts.PackageName,

test/Sema/accessibility_package_import_interface.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
// CHECK-DEP-BC: <MODULE_PACKAGE_NAME abbrevid=6/> blob data = 'myPkg'
2121

2222
// TEST Lib should load Dep.swiftmodule and access package decls if in the same package and error if not
23-
24-
// RUN: %target-swift-frontend -typecheck %t/Lib.swift -package-name myPkg -I %t -verify
23+
// RUN: %target-swift-frontend -typecheck %t/Lib.swift -package-name myPkg -I %t
2524

2625
// RUN: not %target-swift-frontend -typecheck %t/Lib.swift -package-name otherPkg -I %t -Rmodule-loading 2> %t/result-binary-other-pkg.output
2726
// RUN: %FileCheck %s --check-prefix=CHECK-DIFF-PKG < %t/result-binary-other-pkg.output
@@ -45,11 +44,7 @@
4544
// CHECK-DEP-INTER-BC: <MODULE_PACKAGE_NAME abbrevid=7/> blob data = 'myPkg'
4645

4746
// TEST Lib should error on loading Dep built from interface and accessing package symbols (unless usableFromInline or inlinable)
48-
// RUN: not %target-swift-frontend -typecheck %t/Lib.swift -package-name myPkg -I %t 2> %t/result-access.output
49-
// RUN: %FileCheck %s --check-prefix CHECK-LIB < %t/result-access.output
50-
// CHECK-LIB: error: module 'Dep' is in package 'myPkg' but was built from interface; modules of the same package can only be loaded if built from source
51-
// CHECK-LIB: error: cannot find 'packageFunc' in scope
52-
// CHECK-LIB: error: value of type 'PackageKlassUFI' has no member 'packageVar'
47+
// RUN: %target-swift-frontend -typecheck %t/Lib.swift -package-name myPkg -I %t -verify
5348

5449
// TEST Remove and rebuild Dep from source
5550
// RUN: rm %t/Dep.swiftmodule
@@ -114,16 +109,16 @@ public func publicFuncInlinable() {
114109
}
115110

116111
//--- Lib.swift
117-
import Dep
112+
import Dep // expected-error {{module 'Dep' is in package 'myPkg' but was built from interface; modules of the same package can only be loaded if built from source}}
118113

119114
public func libFunc() {
120115
publicFuncInlinable()
121116
publicFunc()
122117
packageFuncInlinable()
123-
packageFunc()
118+
packageFunc() // expected-error {{cannot find 'packageFunc' in scope}}
124119
let x = PackageKlassUFI()
125120
let y = x.packageVarUFI
126-
let z = x.packageVar
121+
let z = x.packageVar // expected-error {{value of type 'PackageKlassUFI' has no member 'packageVar'}}
127122
print(x, y, z)
128123
}
129124

0 commit comments

Comments
 (0)