Skip to content

Commit eb4e9e6

Browse files
authored
Merge pull request #64727 from apple/es-handle-null
[5.9] Handle null package context when returning access scope
2 parents a23f6d9 + e98d5b1 commit eb4e9e6

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3934,10 +3934,15 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39343934
case AccessLevel::Package: {
39353935
auto pkg = resultDC->getPackageContext(/*lookupIfNotCurrent*/ true);
39363936
if (!pkg) {
3937+
// No package context was found; show diagnostics
39373938
auto &d = VD->getASTContext().Diags;
39383939
d.diagnose(VD->getLoc(), diag::access_control_requires_package_name);
3940+
// Instead of reporting and failing early, return the scope of
3941+
// resultDC to allow continuation (should still non-zero exit later)
3942+
return AccessScope(resultDC);
3943+
} else {
3944+
return AccessScope(pkg);
39393945
}
3940-
return AccessScope(pkg);
39413946
}
39423947
case AccessLevel::Public:
39433948
case AccessLevel::Open:

test/diagnostics/package-name-diagnostics.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
// RUN: %empty-directory(%t)
2-
// REQUIRES: rdar106819422
32

43
// Package name should have valid characters
5-
// RUN: not --crash %target-swift-frontend -module-name Logging -package-name My-Logging%Pkg %s -emit-module -emit-module-path %t/Logging.swiftmodule 2> %t/resultA.output
4+
// RUN: not %target-swift-frontend -module-name Logging -package-name My-Logging%Pkg %s -emit-module -emit-module-path %t/Logging.swiftmodule 2> %t/resultA.output
65
// RUN: %FileCheck %s -input-file %t/resultA.output -check-prefix CHECK-BAD
7-
// CHECK-BAD: package name "My-Logging%Pkg" is not a valid identifier
8-
// CHECK-BAD: decl has a package access level but no -package-name was passed
9-
// CHECK-BAD: non-public decl has no formal access scope
6+
// CHECK-BAD: error: package name "My-Logging%Pkg" is not a valid identifier
7+
// CHECK-BAD: error: decl has a package access level but no -package-name was passed
108

119
// Package name should not be empty
12-
// RUN: not --crash %target-swift-frontend -typecheck %s -package-name "" 2>&1 | %FileCheck %s -check-prefix CHECK-EMPTY
13-
// CHECK-EMPTY: package name "" is not a valid identifier
14-
// CHECK-EMPTY: decl has a package access level but no -package-name was passed
15-
// CHECK-EMPTY: non-public decl has no formal access scope
10+
// RUN: not %target-swift-frontend -typecheck %s -package-name "" 2>&1 | %FileCheck %s -check-prefix CHECK-EMPTY
11+
// CHECK-EMPTY: error: package name "" is not a valid identifier
12+
// CHECK-EMPTY: error: decl has a package access level but no -package-name was passed
1613

1714
// If package access level is used but no package-name is passed, it should error
18-
// RUN: not --crash %target-swift-frontend -typecheck %s 2>&1 | %FileCheck %s -check-prefix CHECK-MISSING
19-
// CHECK-MISSING: decl has a package access level but no -package-name was passed
20-
// CHECK-MISSING: non-public decl has no formal access scope
15+
// RUN: not %target-swift-frontend -typecheck %s 2>&1 | %FileCheck %s -check-prefix CHECK-MISSING
16+
// CHECK-MISSING: error: decl has a package access level but no -package-name was passed
2117

2218
// Package name can be same as the module name
2319
// RUN: %target-swift-frontend -module-name Logging -package-name Logging %s -emit-module -emit-module-path %t/Logging.swiftmodule

0 commit comments

Comments
 (0)