Skip to content

Commit 3732c75

Browse files
committed
Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
1 parent 1318bf5 commit 3732c75

10 files changed

+35
-49
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,10 +2310,10 @@ NOTE(module_imported_here,none,
23102310
"module %0 imported as '%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' here",
23112311
(Identifier, AccessLevel))
23122312
NOTE(decl_import_via_here,none,
2313-
"%0 %1 imported as "
2314-
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}2' "
2315-
"from %3 here",
2316-
(DescriptiveDeclKind, DeclName, AccessLevel, Identifier))
2313+
"%kind0 imported as "
2314+
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' "
2315+
"from %2 here",
2316+
(const ValueDecl *, AccessLevel, Identifier))
23172317

23182318
// Opaque return types
23192319
ERROR(opaque_type_invalid_constraint,none,
@@ -6500,14 +6500,14 @@ ERROR(local_type_in_inlinable_function,
65006500
(Identifier, unsigned))
65016501

65026502
ERROR(resilience_decl_unavailable,
6503-
none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and "
6504-
"cannot be referenced from " FRAGILE_FUNC_KIND "3",
6505-
(DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool))
6503+
none, "%kind0 is %select{private|fileprivate|internal|package|%error|%error}1 and "
6504+
"cannot be referenced from " FRAGILE_FUNC_KIND "2",
6505+
(const ValueDecl *, AccessLevel, unsigned))
65066506

65076507
WARNING(resilience_decl_unavailable_warn,
6508-
none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and "
6509-
"should not be referenced from " FRAGILE_FUNC_KIND "3",
6510-
(DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool))
6508+
none, "%kind0 is %select{private|fileprivate|internal|package|%error|%error}1 and "
6509+
"should not be referenced from " FRAGILE_FUNC_KIND "2",
6510+
(const ValueDecl *, AccessLevel, unsigned))
65116511

65126512
ERROR(inlinable_decl_ref_from_hidden_module,
65136513
none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 "
@@ -6547,10 +6547,8 @@ ERROR(availability_macro_in_inlinable, none,
65476547
#undef FRAGILE_FUNC_KIND
65486548

65496549
NOTE(resilience_decl_declared_here,
6550-
none, DECL_OR_ACCESSOR "2 %1 is not '@usableFromInline' or public",
6551-
(DescriptiveDeclKind, DeclName, bool))
6552-
6553-
#undef DECL_OR_ACCESSOR
6550+
none, "%kind0 is not '@usableFromInline' or public",
6551+
(const ValueDecl *))
65546552

65556553
ERROR(class_designated_init_inlinable_resilient,none,
65566554
"initializer for class %0 is "

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,10 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
105105
downgradeToWarning = DowngradeToWarning::Yes;
106106
}
107107

108-
auto diagName = D->getName();
109-
bool isAccessor = false;
110-
111108
// Swift 4.2 did not check accessor accessibility.
112109
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
113-
isAccessor = true;
114-
115110
if (!Context.isSwiftVersionAtLeast(5))
116111
downgradeToWarning = DowngradeToWarning::Yes;
117-
118-
// For accessors, diagnose with the name of the storage instead of the
119-
// implicit '_'.
120-
diagName = accessor->getStorage()->getName();
121112
}
122113

123114
// Swift 5.0 did not check the underlying types of local typealiases.
@@ -131,18 +122,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
131122
auto diagAccessLevel = std::min(declAccessScope.accessLevelForDiagnostics(),
132123
importAccessLevel);
133124

134-
Context.Diags.diagnose(loc, diagID, D->getDescriptiveKind(), diagName,
135-
diagAccessLevel,
136-
fragileKind.getSelector(), isAccessor);
125+
Context.Diags.diagnose(loc, diagID, D, diagAccessLevel,
126+
fragileKind.getSelector());
137127

138-
Context.Diags.diagnose(D, diag::resilience_decl_declared_here,
139-
D->getDescriptiveKind(), diagName, isAccessor);
128+
Context.Diags.diagnose(D, diag::resilience_decl_declared_here, D);
140129

141130
if (problematicImport.has_value() &&
142131
diagAccessLevel == importAccessLevel) {
143132
Context.Diags.diagnose(problematicImport->accessLevelLoc,
144-
diag::decl_import_via_here,
145-
D->getDescriptiveKind(), diagName,
133+
diag::decl_import_via_here, D,
146134
problematicImport->accessLevel,
147135
problematicImport->module.importedModule->getName());
148136
}

lib/Sema/TypeCheckAccess.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ static void noteLimitingImport(ASTContext &ctx,
354354
"a public import shouldn't limit the access level of a decl");
355355

356356
if (auto ITR = dyn_cast_or_null<IdentTypeRepr>(complainRepr)) {
357-
const ValueDecl *VD = ITR->getBoundDecl();
358-
ctx.Diags.diagnose(limitImport->accessLevelLoc, diag::decl_import_via_here,
359-
DescriptiveDeclKind::Type,
360-
VD->getName(),
357+
ValueDecl *VD = ITR->getBoundDecl();
358+
ctx.Diags.diagnose(limitImport->accessLevelLoc,
359+
diag::decl_import_via_here,
360+
VD,
361361
limitImport->accessLevel,
362362
limitImport->module.importedModule->getName());
363363
} else {

test/Compatibility/attr_inlinable_swift42.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ enum InternalEnum {
1818
}
1919

2020
public struct HasInternalSetProperty {
21-
public internal(set) var x: Int // expected-note {{setter for 'x' is not '@usableFromInline' or public}}
21+
public internal(set) var x: Int // expected-note {{setter for property 'x' is not '@usableFromInline' or public}}
2222

2323
@inlinable public mutating func setsX() {
24-
x = 10 // expected-warning {{setter for 'x' is internal and should not be referenced from an '@inlinable' function}}
24+
x = 10 // expected-warning {{setter for property 'x' is internal and should not be referenced from an '@inlinable' function}}
2525
}
2626
}
2727

test/SPI/local_spi_decls.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' cannot be us
3737
spiFunc() // expected-error {{global function 'spiFunc()' cannot be used in an '@inlinable' function because it is SPI}}
3838
_ = SPIClass() // expected-error {{class 'SPIClass' cannot be used in an '@inlinable' function because it is SPI}}
3939
// expected-error@-1 {{initializer 'init()' cannot be used in an '@inlinable' function because it is SPI}}
40-
globalArrayWithSPISetter = [] // expected-error {{setter 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
41-
globalArrayWithSPISetter.append(0) // expected-error {{setter 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
40+
globalArrayWithSPISetter = [] // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
41+
globalArrayWithSPISetter.append(0) // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
4242
}
4343

4444
@_spi(S) public struct SPIStruct {

test/Sema/access-level-import-diag-priority.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public struct PrivateImportType {}
3333

3434
//--- Client.swift
3535
public import PublicLib
36-
package import PackageLib // expected-note {{type 'PackageImportType' imported as 'package' from 'PackageLib' here}}
37-
internal import InternalLib // expected-note {{type 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
38-
fileprivate import FileprivateLib // expected-note 2 {{type 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
39-
private import PrivateLib // expected-note 2 {{type 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
36+
package import PackageLib // expected-note {{struct 'PackageImportType' imported as 'package' from 'PackageLib' here}}
37+
internal import InternalLib // expected-note {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
38+
fileprivate import FileprivateLib // expected-note 2 {{struct 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
39+
private import PrivateLib // expected-note 2 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
4040

4141
/// Simple ordering
4242
public func publicFuncUsesPrivate(_ a: PublicImportType, b: PackageImportType, c: InternalImportType, d: FileprivateImportType, e: PrivateImportType) { // expected-error {{function cannot be declared public because its parameter uses a private type}}
@@ -64,7 +64,7 @@ public func publicFuncUsesPrivateScambled(_ a: PublicImportType, d: FileprivateI
6464
//--- LocalVsImportClient.swift
6565
public import PublicLib
6666
internal import InternalLib
67-
fileprivate import FileprivateLib // expected-note {{type 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
67+
fileprivate import FileprivateLib // expected-note {{struct 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
6868

6969
fileprivate struct LocalType {} // expected-note 3 {{type declared here}}
7070
public func localVsImportedType1(a: LocalType, b: InternalImportType) {} // expected-error {{function cannot be declared public because its parameter uses a fileprivate type}}

test/Sema/access-level-import-exportability.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public struct PrivateLibWrapper<T> {
121121
//--- MinimalClient.swift
122122
public import PublicLib
123123
package import PackageLib
124-
internal import InternalLib // expected-note@:1 {{type 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
125-
fileprivate import FileprivateLib // expected-note@:1 {{type 'FileprivateImportClass' imported as 'fileprivate' from 'FileprivateLib' here}}
124+
internal import InternalLib // expected-note@:1 {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
125+
fileprivate import FileprivateLib // expected-note@:1 {{class 'FileprivateImportClass' imported as 'fileprivate' from 'FileprivateLib' here}}
126126
private import PrivateLib
127127

128128
public func PublicFuncUsesInternal(_: InternalImportType) { // expected-error {{function cannot be declared public because its parameter uses an internal type}}

test/attr/attr_inlinable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ public struct KeypathStruct {
307307
}
308308

309309
public struct HasInternalSetProperty {
310-
public internal(set) var x: Int // expected-note {{setter for 'x' is not '@usableFromInline' or public}}
310+
public internal(set) var x: Int // expected-note {{setter for property 'x' is not '@usableFromInline' or public}}
311311

312312
@inlinable public mutating func setsX() {
313-
x = 10 // expected-error {{setter for 'x' is internal and cannot be referenced from an '@inlinable' function}}
313+
x = 10 // expected-error {{setter for property 'x' is internal and cannot be referenced from an '@inlinable' function}}
314314
}
315315
}
316316

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
public struct OtherStruct {
22
public internal(set) static var staticProp = 123
3-
// expected-note@-1 {{setter for 'staticProp' is not '@usableFromInline' or public}}
3+
// expected-note@-1 {{setter for static property 'staticProp' is not '@usableFromInline' or public}}
44
}

test/multifile/inlinable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@frozen public struct HasInitExpr {
44
public var hasInlinableInit = mutatingFunc(&OtherStruct.staticProp)
5-
// expected-warning@-1 {{setter for 'staticProp' is internal and should not be referenced from a property initializer in a '@frozen' type}}
5+
// expected-warning@-1 {{setter for static property 'staticProp' is internal and should not be referenced from a property initializer in a '@frozen' type}}
66
}
77

88
public func mutatingFunc(_: inout Int) -> Int {

0 commit comments

Comments
 (0)