Skip to content

Commit 79a2ff5

Browse files
authored
Merge pull request #66189 from apple/es-diag
Improve diagnostics when package acl is used but no package-name is passed
2 parents dfed93d + 854e7dc commit 79a2ff5

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,8 +1806,8 @@ WARNING(access_control_non_objc_open_member,none,
18061806
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
18071807
(DescriptiveDeclKind))
18081808
ERROR(access_control_requires_package_name, none,
1809-
"decl has a package access level but no -package-name was passed",
1810-
())
1809+
"%0 has a package access level but no -package-name was specified: %1",
1810+
(Identifier, StringRef))
18111811
ERROR(invalid_decl_attribute,none,
18121812
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
18131813
ERROR(attr_invalid_on_decl_kind,none,

lib/AST/Decl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3981,7 +3981,11 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39813981
if (!shouldSkipDiag) {
39823982
// No package context was found; show diagnostics
39833983
auto &d = VD->getASTContext().Diags;
3984-
d.diagnose(VD->getLoc(), diag::access_control_requires_package_name);
3984+
auto filename = srcFile ? srcFile->getFilename() : resultDC->getParentModule()->getBaseIdentifier().str();
3985+
d.diagnose(VD->getLoc(),
3986+
diag::access_control_requires_package_name,
3987+
VD->getBaseIdentifier(),
3988+
filename);
39853989
}
39863990
// Instead of reporting and failing early, return the scope of resultDC to
39873991
// allow continuation (should still non-zero exit later if in script mode)

test/diagnostics/package-name-diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// Package name should not be empty
44
// RUN: not %target-swift-frontend -typecheck %s -package-name "" 2>&1 | %FileCheck %s -check-prefix CHECK-EMPTY
55
// CHECK-EMPTY: error: package-name is empty
6-
// CHECK-EMPTY: error: decl has a package access level but no -package-name was passed
6+
// CHECK-EMPTY: error: 'log' has a package access level but no -package-name was specified: {{.*}}.swift
77

88
// If package access level is used but no package-name is passed, it should error
99
// RUN: not %target-swift-frontend -typecheck %s 2>&1 | %FileCheck %s -check-prefix CHECK-MISSING
10-
// CHECK-MISSING: error: decl has a package access level but no -package-name was passed
10+
// CHECK-MISSING: error: 'log' has a package access level but no -package-name was specified: {{.*}}.swift
1111

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

0 commit comments

Comments
 (0)