@@ -3973,10 +3973,12 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39733973 auto pkg = resultDC->getPackageContext (/* lookupIfNotCurrent*/ true );
39743974 if (!pkg) {
39753975 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) {
39803982 // No package context was found; show diagnostics
39813983 auto &d = VD->getASTContext ().Diags ;
39823984 d.diagnose (VD->getLoc (), diag::access_control_requires_package_name);
@@ -4175,15 +4177,16 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
41754177 }
41764178 case AccessLevel::Package: {
41774179 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
41854185 return true ;
41864186 }
4187+ auto srcPkg = sourceDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4188+ auto usePkg = useDC->getPackageContext (/* lookupIfNotCurrent*/ true );
4189+ return srcPkg && usePkg && usePkg->isSamePackageAs (srcPkg);
41874190 }
41884191 case AccessLevel::Public:
41894192 case AccessLevel::Open:
0 commit comments