@@ -3955,11 +3955,17 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39553955 case AccessLevel::Package: {
39563956 auto pkg = resultDC->getPackageContext (/* lookupIfNotCurrent*/ true );
39573957 if (!pkg) {
3958- // No package context was found; show diagnostics
3959- auto &d = VD->getASTContext ().Diags ;
3960- d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
3961- // Instead of reporting and failing early, return the scope of
3962- // resultDC to allow continuation (should still non-zero exit later)
3958+ auto srcFile = resultDC->getParentSourceFile ();
3959+ // Check if the file containing package decls is an interface file; if a public
3960+ // interface contains package decls, they must be inlinable and do not need a
3961+ // package-name, so don't show diagnostics in that case.
3962+ if (srcFile && srcFile->Kind != SourceFileKind::Interface) {
3963+ // No package context was found; show diagnostics
3964+ auto &d = VD->getASTContext ().Diags ;
3965+ d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
3966+ }
3967+ // Instead of reporting and failing early, return the scope of resultDC to
3968+ // allow continuation (should still non-zero exit later if in script mode)
39633969 return AccessScope (resultDC);
39643970 } else {
39653971 return AccessScope (pkg);
@@ -4151,9 +4157,16 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
41514157 return useSF && useSF->hasTestableOrPrivateImport (access, sourceModule);
41524158 }
41534159 case AccessLevel::Package: {
4154- auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4155- auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4156- return usePkg->isSamePackageAs (srcPkg);
4160+ auto srcFile = sourceDC->getParentSourceFile ();
4161+ if (srcFile && srcFile->Kind != SourceFileKind::Interface) {
4162+ auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4163+ auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4164+ return usePkg->isSamePackageAs (srcPkg);
4165+ } else {
4166+ // If source file is interface, package decls must be inlinable,
4167+ // essentially treated public so return true (see AccessLevel::Public)
4168+ return true ;
4169+ }
41574170 }
41584171 case AccessLevel::Public:
41594172 case AccessLevel::Open:
0 commit comments