Skip to content

Commit

Permalink
Merge pull request #66189 from apple/es-diag
Browse files Browse the repository at this point in the history
Improve diagnostics when package acl is used but no package-name is passed
  • Loading branch information
elsh committed May 27, 2023
2 parents dfed93d + 854e7dc commit 79a2ff5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,8 @@ WARNING(access_control_non_objc_open_member,none,
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
(DescriptiveDeclKind))
ERROR(access_control_requires_package_name, none,
"decl has a package access level but no -package-name was passed",
())
"%0 has a package access level but no -package-name was specified: %1",
(Identifier, StringRef))
ERROR(invalid_decl_attribute,none,
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
ERROR(attr_invalid_on_decl_kind,none,
Expand Down
6 changes: 5 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3981,7 +3981,11 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
if (!shouldSkipDiag) {
// No package context was found; show diagnostics
auto &d = VD->getASTContext().Diags;
d.diagnose(VD->getLoc(), diag::access_control_requires_package_name);
auto filename = srcFile ? srcFile->getFilename() : resultDC->getParentModule()->getBaseIdentifier().str();
d.diagnose(VD->getLoc(),
diag::access_control_requires_package_name,
VD->getBaseIdentifier(),
filename);
}
// Instead of reporting and failing early, return the scope of resultDC to
// allow continuation (should still non-zero exit later if in script mode)
Expand Down
4 changes: 2 additions & 2 deletions test/diagnostics/package-name-diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// Package name should not be empty
// RUN: not %target-swift-frontend -typecheck %s -package-name "" 2>&1 | %FileCheck %s -check-prefix CHECK-EMPTY
// CHECK-EMPTY: error: package-name is empty
// CHECK-EMPTY: error: decl has a package access level but no -package-name was passed
// CHECK-EMPTY: error: 'log' has a package access level but no -package-name was specified: {{.*}}.swift

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

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

0 comments on commit 79a2ff5

Please sign in to comment.