@@ -3972,11 +3972,17 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39723972 case AccessLevel::Package: {
39733973 auto pkg = resultDC->getPackageContext (/* lookupIfNotCurrent*/ true );
39743974 if (!pkg) {
3975- // No package context was found; show diagnostics
3976- auto &d = VD->getASTContext ().Diags ;
3977- d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
3978- // Instead of reporting and failing early, return the scope of
3979- // resultDC to allow continuation (should still non-zero exit later)
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) {
3980+ // No package context was found; show diagnostics
3981+ auto &d = VD->getASTContext ().Diags ;
3982+ d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
3983+ }
3984+ // Instead of reporting and failing early, return the scope of resultDC to
3985+ // allow continuation (should still non-zero exit later if in script mode)
39803986 return AccessScope (resultDC);
39813987 } else {
39823988 return AccessScope (pkg);
@@ -4168,9 +4174,16 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
41684174 return useSF && useSF->hasTestableOrPrivateImport (access, sourceModule);
41694175 }
41704176 case AccessLevel::Package: {
4171- auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4172- auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4173- return usePkg->isSamePackageAs (srcPkg);
4177+ 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)
4185+ return true ;
4186+ }
41744187 }
41754188 case AccessLevel::Public:
41764189 case AccessLevel::Open:
0 commit comments