Skip to content

Commit 1d7ef25

Browse files
authored
Merge pull request #64707 from apple/es-crash
Handle null package context when returning access scope
2 parents e450302 + 60b264b commit 1d7ef25

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
@@ -3933,10 +3933,15 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39333933
case AccessLevel::Package: {
39343934
auto pkg = resultDC->getPackageContext(/*lookupIfNotCurrent*/ true);
39353935
if (!pkg) {
3936+
// No package context was found; show diagnostics
39363937
auto &d = VD->getASTContext().Diags;
39373938
d.diagnose(VD->getLoc(), diag::access_control_requires_package_name);
3939+
// Instead of reporting and failing early, return the scope of
3940+
// resultDC to allow continuation (should still non-zero exit later)
3941+
return AccessScope(resultDC);
3942+
} else {
3943+
return AccessScope(pkg);
39383944
}
3939-
return AccessScope(pkg);
39403945
}
39413946
case AccessLevel::Public:
39423947
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)