mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
This commit is contained in:
@@ -2310,10 +2310,10 @@ NOTE(module_imported_here,none,
|
||||
"module %0 imported as '%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' here",
|
||||
(Identifier, AccessLevel))
|
||||
NOTE(decl_import_via_here,none,
|
||||
"%0 %1 imported as "
|
||||
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}2' "
|
||||
"from %3 here",
|
||||
(DescriptiveDeclKind, DeclName, AccessLevel, Identifier))
|
||||
"%kind0 imported as "
|
||||
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' "
|
||||
"from %2 here",
|
||||
(const ValueDecl *, AccessLevel, Identifier))
|
||||
|
||||
// Opaque return types
|
||||
ERROR(opaque_type_invalid_constraint,none,
|
||||
@@ -6500,14 +6500,14 @@ ERROR(local_type_in_inlinable_function,
|
||||
(Identifier, unsigned))
|
||||
|
||||
ERROR(resilience_decl_unavailable,
|
||||
none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and "
|
||||
"cannot be referenced from " FRAGILE_FUNC_KIND "3",
|
||||
(DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool))
|
||||
none, "%kind0 is %select{private|fileprivate|internal|package|%error|%error}1 and "
|
||||
"cannot be referenced from " FRAGILE_FUNC_KIND "2",
|
||||
(const ValueDecl *, AccessLevel, unsigned))
|
||||
|
||||
WARNING(resilience_decl_unavailable_warn,
|
||||
none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and "
|
||||
"should not be referenced from " FRAGILE_FUNC_KIND "3",
|
||||
(DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool))
|
||||
none, "%kind0 is %select{private|fileprivate|internal|package|%error|%error}1 and "
|
||||
"should not be referenced from " FRAGILE_FUNC_KIND "2",
|
||||
(const ValueDecl *, AccessLevel, unsigned))
|
||||
|
||||
ERROR(inlinable_decl_ref_from_hidden_module,
|
||||
none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 "
|
||||
@@ -6547,10 +6547,8 @@ ERROR(availability_macro_in_inlinable, none,
|
||||
#undef FRAGILE_FUNC_KIND
|
||||
|
||||
NOTE(resilience_decl_declared_here,
|
||||
none, DECL_OR_ACCESSOR "2 %1 is not '@usableFromInline' or public",
|
||||
(DescriptiveDeclKind, DeclName, bool))
|
||||
|
||||
#undef DECL_OR_ACCESSOR
|
||||
none, "%kind0 is not '@usableFromInline' or public",
|
||||
(const ValueDecl *))
|
||||
|
||||
ERROR(class_designated_init_inlinable_resilient,none,
|
||||
"initializer for class %0 is "
|
||||
|
||||
@@ -105,19 +105,10 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
|
||||
downgradeToWarning = DowngradeToWarning::Yes;
|
||||
}
|
||||
|
||||
auto diagName = D->getName();
|
||||
bool isAccessor = false;
|
||||
|
||||
// Swift 4.2 did not check accessor accessibility.
|
||||
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
|
||||
isAccessor = true;
|
||||
|
||||
if (!Context.isSwiftVersionAtLeast(5))
|
||||
downgradeToWarning = DowngradeToWarning::Yes;
|
||||
|
||||
// For accessors, diagnose with the name of the storage instead of the
|
||||
// implicit '_'.
|
||||
diagName = accessor->getStorage()->getName();
|
||||
}
|
||||
|
||||
// Swift 5.0 did not check the underlying types of local typealiases.
|
||||
@@ -131,18 +122,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
|
||||
auto diagAccessLevel = std::min(declAccessScope.accessLevelForDiagnostics(),
|
||||
importAccessLevel);
|
||||
|
||||
Context.Diags.diagnose(loc, diagID, D->getDescriptiveKind(), diagName,
|
||||
diagAccessLevel,
|
||||
fragileKind.getSelector(), isAccessor);
|
||||
Context.Diags.diagnose(loc, diagID, D, diagAccessLevel,
|
||||
fragileKind.getSelector());
|
||||
|
||||
Context.Diags.diagnose(D, diag::resilience_decl_declared_here,
|
||||
D->getDescriptiveKind(), diagName, isAccessor);
|
||||
Context.Diags.diagnose(D, diag::resilience_decl_declared_here, D);
|
||||
|
||||
if (problematicImport.has_value() &&
|
||||
diagAccessLevel == importAccessLevel) {
|
||||
Context.Diags.diagnose(problematicImport->accessLevelLoc,
|
||||
diag::decl_import_via_here,
|
||||
D->getDescriptiveKind(), diagName,
|
||||
diag::decl_import_via_here, D,
|
||||
problematicImport->accessLevel,
|
||||
problematicImport->module.importedModule->getName());
|
||||
}
|
||||
|
||||
@@ -354,10 +354,10 @@ static void noteLimitingImport(ASTContext &ctx,
|
||||
"a public import shouldn't limit the access level of a decl");
|
||||
|
||||
if (auto ITR = dyn_cast_or_null<IdentTypeRepr>(complainRepr)) {
|
||||
const ValueDecl *VD = ITR->getBoundDecl();
|
||||
ctx.Diags.diagnose(limitImport->accessLevelLoc, diag::decl_import_via_here,
|
||||
DescriptiveDeclKind::Type,
|
||||
VD->getName(),
|
||||
ValueDecl *VD = ITR->getBoundDecl();
|
||||
ctx.Diags.diagnose(limitImport->accessLevelLoc,
|
||||
diag::decl_import_via_here,
|
||||
VD,
|
||||
limitImport->accessLevel,
|
||||
limitImport->module.importedModule->getName());
|
||||
} else {
|
||||
|
||||
@@ -18,10 +18,10 @@ enum InternalEnum {
|
||||
}
|
||||
|
||||
public struct HasInternalSetProperty {
|
||||
public internal(set) var x: Int // expected-note {{setter for 'x' is not '@usableFromInline' or public}}
|
||||
public internal(set) var x: Int // expected-note {{setter for property 'x' is not '@usableFromInline' or public}}
|
||||
|
||||
@inlinable public mutating func setsX() {
|
||||
x = 10 // expected-warning {{setter for 'x' is internal and should not be referenced from an '@inlinable' function}}
|
||||
x = 10 // expected-warning {{setter for property 'x' is internal and should not be referenced from an '@inlinable' function}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' cannot be us
|
||||
spiFunc() // expected-error {{global function 'spiFunc()' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
_ = SPIClass() // expected-error {{class 'SPIClass' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
// expected-error@-1 {{initializer 'init()' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
globalArrayWithSPISetter = [] // expected-error {{setter 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
globalArrayWithSPISetter.append(0) // expected-error {{setter 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
globalArrayWithSPISetter = [] // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
globalArrayWithSPISetter.append(0) // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
|
||||
}
|
||||
|
||||
@_spi(S) public struct SPIStruct {
|
||||
|
||||
@@ -33,10 +33,10 @@ public struct PrivateImportType {}
|
||||
|
||||
//--- Client.swift
|
||||
public import PublicLib
|
||||
package import PackageLib // expected-note {{type 'PackageImportType' imported as 'package' from 'PackageLib' here}}
|
||||
internal import InternalLib // expected-note {{type 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
|
||||
fileprivate import FileprivateLib // expected-note 2 {{type 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
private import PrivateLib // expected-note 2 {{type 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
|
||||
package import PackageLib // expected-note {{struct 'PackageImportType' imported as 'package' from 'PackageLib' here}}
|
||||
internal import InternalLib // expected-note {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
|
||||
fileprivate import FileprivateLib // expected-note 2 {{struct 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
private import PrivateLib // expected-note 2 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
|
||||
|
||||
/// Simple ordering
|
||||
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
|
||||
//--- LocalVsImportClient.swift
|
||||
public import PublicLib
|
||||
internal import InternalLib
|
||||
fileprivate import FileprivateLib // expected-note {{type 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
fileprivate import FileprivateLib // expected-note {{struct 'FileprivateImportType' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
|
||||
fileprivate struct LocalType {} // expected-note 3 {{type declared here}}
|
||||
public func localVsImportedType1(a: LocalType, b: InternalImportType) {} // expected-error {{function cannot be declared public because its parameter uses a fileprivate type}}
|
||||
|
||||
@@ -121,8 +121,8 @@ public struct PrivateLibWrapper<T> {
|
||||
//--- MinimalClient.swift
|
||||
public import PublicLib
|
||||
package import PackageLib
|
||||
internal import InternalLib // expected-note@:1 {{type 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
|
||||
fileprivate import FileprivateLib // expected-note@:1 {{type 'FileprivateImportClass' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
internal import InternalLib // expected-note@:1 {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
|
||||
fileprivate import FileprivateLib // expected-note@:1 {{class 'FileprivateImportClass' imported as 'fileprivate' from 'FileprivateLib' here}}
|
||||
private import PrivateLib
|
||||
|
||||
public func PublicFuncUsesInternal(_: InternalImportType) { // expected-error {{function cannot be declared public because its parameter uses an internal type}}
|
||||
|
||||
@@ -307,10 +307,10 @@ public struct KeypathStruct {
|
||||
}
|
||||
|
||||
public struct HasInternalSetProperty {
|
||||
public internal(set) var x: Int // expected-note {{setter for 'x' is not '@usableFromInline' or public}}
|
||||
public internal(set) var x: Int // expected-note {{setter for property 'x' is not '@usableFromInline' or public}}
|
||||
|
||||
@inlinable public mutating func setsX() {
|
||||
x = 10 // expected-error {{setter for 'x' is internal and cannot be referenced from an '@inlinable' function}}
|
||||
x = 10 // expected-error {{setter for property 'x' is internal and cannot be referenced from an '@inlinable' function}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public struct OtherStruct {
|
||||
public internal(set) static var staticProp = 123
|
||||
// expected-note@-1 {{setter for 'staticProp' is not '@usableFromInline' or public}}
|
||||
// expected-note@-1 {{setter for static property 'staticProp' is not '@usableFromInline' or public}}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@frozen public struct HasInitExpr {
|
||||
public var hasInlinableInit = mutatingFunc(&OtherStruct.staticProp)
|
||||
// expected-warning@-1 {{setter for 'staticProp' is internal and should not be referenced from a property initializer in a '@frozen' type}}
|
||||
// expected-warning@-1 {{setter for static property 'staticProp' is internal and should not be referenced from a property initializer in a '@frozen' type}}
|
||||
}
|
||||
|
||||
public func mutatingFunc(_: inout Int) -> Int {
|
||||
|
||||
Reference in New Issue
Block a user