Skip to content

Commit 4cd1048

Browse files
committed
[Sema] Name the decl in the error on package level without a package
1 parent 1a4a47f commit 4cd1048

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,9 +1935,9 @@ WARNING(access_control_non_objc_open_member,none,
19351935
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
19361936
(DescriptiveDeclKind))
19371937
ERROR(access_control_requires_package_name, none,
1938-
"the package access level requires a package name; "
1939-
"set it with the compiler flag -package-name",
1940-
())
1938+
"the package access level %select{|used on %1 }0"
1939+
"requires a package name; set it with the compiler flag -package-name",
1940+
(bool, const Decl*))
19411941
ERROR(invalid_decl_attribute,none,
19421942
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
19431943
ERROR(attr_invalid_on_decl_kind,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,8 @@ bool AttributeChecker::visitAbstractAccessControlAttr(
10231023
D->getASTContext().LangOpts.PackageName.empty() &&
10241024
File && File->Kind != SourceFileKind::Interface) {
10251025
// `package` modifier used outside of a package.
1026-
diagnose(attr->getLocation(), diag::access_control_requires_package_name);
1026+
diagnose(attr->getLocation(), diag::access_control_requires_package_name,
1027+
isa<ValueDecl>(D), D);
10271028
return true;
10281029
}
10291030

test/attr/package-modifier-outside-of-package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public struct PackageImportType {}
1616
//--- Client.swift
1717
package import PackageLib // expected-error {{the package access level requires a package name; set it with the compiler flag -package-name}}
1818

19-
package struct PackageStruct { // expected-error {{the package access level requires a package name; set it with the compiler flag -package-name}}
20-
package func explicitlyPackage() {} // expected-error {{the package access level requires a package name; set it with the compiler flag -package-name}}
19+
package struct PackageStruct { // expected-error {{the package access level used on 'PackageStruct' requires a package name; set it with the compiler flag -package-name}}
20+
package func explicitlyPackage() {} // expected-error {{the package access level used on 'explicitlyPackage()' requires a package name; set it with the compiler flag -package-name}}
2121
}
2222

2323
public struct PublicStruct {}

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: the package access level requires a package name; set it with the compiler flag -package-name
6+
// CHECK-EMPTY: error: the package access level used on 'log()' requires a package name; set it with the compiler flag -package-name
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: the package access level requires a package name; set it with the compiler flag -package-name
10+
// CHECK-MISSING: error: the package access level used on 'log()' requires a package name; set it with the compiler flag -package-name
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)