Skip to content

Commit 61dd300

Browse files
committed
Improve diagnostics when package acl is used but no package-name is passed
1 parent c2c2414 commit 61dd300

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
@@ -1782,8 +1782,8 @@ WARNING(access_control_non_objc_open_member,none,
17821782
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
17831783
(DescriptiveDeclKind))
17841784
ERROR(access_control_requires_package_name, none,
1785-
"decl has a package access level but no -package-name was passed",
1786-
())
1785+
"%0 has a package access level but no -package-name was passed: %1",
1786+
(Identifier, StringRef))
17871787
ERROR(invalid_decl_attribute,none,
17881788
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
17891789
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
@@ -3979,7 +3979,11 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
39793979
if (srcFile && srcFile->Kind != SourceFileKind::Interface) {
39803980
// No package context was found; show diagnostics
39813981
auto &d = VD->getASTContext().Diags;
3982-
d.diagnose(VD->getLoc(), diag::access_control_requires_package_name);
3982+
auto filename = srcFile ? srcFile->getFilename() : resultDC->getParentModule()->getBaseIdentifier().str();
3983+
d.diagnose(VD->getLoc(),
3984+
diag::access_control_requires_package_name,
3985+
VD->getBaseIdentifier(),
3986+
filename);
39833987
}
39843988
// Instead of reporting and failing early, return the scope of resultDC to
39853989
// 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 passed: {{.*}}.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 passed: {{.*}}.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)