@@ -3973,10 +3973,12 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
3973
3973
auto pkg = resultDC->getPackageContext (/* lookupIfNotCurrent*/ true );
3974
3974
if (!pkg) {
3975
3975
auto srcFile = resultDC->getParentSourceFile ();
3976
- // Check if the file containing package decls is an interface file; if a public
3977
- // interface contains package decls, they must be inlinable and do not need a
3978
- // package-name, so don't show diagnostics in that case.
3979
- if (srcFile && srcFile->Kind != SourceFileKind::Interface) {
3976
+ // Check if the file containing package decls is an interface file; if an
3977
+ // interface file contains package decls, they must be usableFromInline or
3978
+ // inlinable and are accessed within the defining module, so package-name
3979
+ // is not needed; do not show diagnostics in such case.
3980
+ auto shouldSkipDiag = srcFile && srcFile->Kind == SourceFileKind::Interface;
3981
+ if (!shouldSkipDiag) {
3980
3982
// No package context was found; show diagnostics
3981
3983
auto &d = VD->getASTContext ().Diags ;
3982
3984
d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
@@ -4175,15 +4177,16 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
4175
4177
}
4176
4178
case AccessLevel::Package: {
4177
4179
auto srcFile = sourceDC->getParentSourceFile ();
4178
- if (srcFile && srcFile->Kind != SourceFileKind::Interface) {
4179
- auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4180
- auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4181
- return usePkg->isSamePackageAs (srcPkg);
4182
- } else {
4183
- // If source file is interface, package decls must be inlinable,
4184
- // essentially treated public so return true (see AccessLevel::Public)
4180
+
4181
+ // srcFile could be null if VD decl is from an imported .swiftmodule
4182
+ if (srcFile && srcFile->Kind == SourceFileKind::Interface) {
4183
+ // If source file is interface, package decls must be usableFromInline or
4184
+ // inlinable, and are accessed only within the defining module so return true
4185
4185
return true ;
4186
4186
}
4187
+ auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4188
+ auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4189
+ return srcPkg && usePkg && usePkg->isSamePackageAs (srcPkg);
4187
4190
}
4188
4191
case AccessLevel::Public:
4189
4192
case AccessLevel::Open:
0 commit comments