Skip to content

Commit 8eaad45

Browse files
authored
Merge pull request #78701 from tshortli/revert-refactor-diagnose-explicit-unavailability-6.1
[6.1] Sema: Partially revert #77236
2 parents 1ac9fd8 + c520fd6 commit 8eaad45

11 files changed

+21
-80
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,7 @@ void swift::diagnoseOverrideOfUnavailableDecl(ValueDecl *override,
29352935

29362936
/// Emit a diagnostic for references to declarations that have been
29372937
/// marked as unavailable, either through "unavailable" or "obsoleted:".
2938-
static bool diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
2938+
bool swift::diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
29392939
const ExportContext &Where,
29402940
const Expr *call,
29412941
DeclAvailabilityFlags Flags) {
@@ -4174,6 +4174,8 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *D, SourceRange R,
41744174
const Expr *call,
41754175
const ExportContext &Where,
41764176
DeclAvailabilityFlags Flags) {
4177+
assert(!Where.isImplicit());
4178+
41774179
// Generic parameters are always available.
41784180
if (isa<GenericTypeParamDecl>(D))
41794181
return false;

lib/Sema/TypeCheckAvailability.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ void diagnoseOverrideOfUnavailableDecl(ValueDecl *override,
241241
const ValueDecl *base,
242242
const AvailableAttr *attr);
243243

244+
/// Emit a diagnostic for references to declarations that have been
245+
/// marked as unavailable, either through "unavailable" or "obsoleted:".
246+
bool diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
247+
const ExportContext &Where,
248+
const Expr *call,
249+
DeclAvailabilityFlags Flags = std::nullopt);
250+
244251
/// Checks whether a declaration should be considered unavailable when referred
245252
/// to in the given declaration context and availability context and, if so,
246253
/// returns a result that describes the unsatisfied constraint.

lib/Sema/TypeCheckStorage.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,13 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
12231223
// Check for availability of wrappedValue.
12241224
if (accessor->getAccessorKind() == AccessorKind::Get ||
12251225
isYieldingImmutableAccessor(accessor->getAccessorKind())) {
1226-
diagnoseDeclAvailability(
1227-
wrappedValue,
1228-
var->getAttachedPropertyWrappers()[i]->getRangeWithAt(), nullptr,
1229-
ExportContext::forDeclSignature(accessor));
1226+
if (wrappedValue->getAttrs().getUnavailable(ctx)) {
1227+
ExportContext where = ExportContext::forDeclSignature(var);
1228+
diagnoseExplicitUnavailability(
1229+
wrappedValue,
1230+
var->getAttachedPropertyWrappers()[i]->getRangeWithAt(),
1231+
where, nullptr);
1232+
}
12301233
}
12311234

12321235
underlyingVars.push_back({ wrappedValue, isWrapperRefLValue });

test/SPI/spi-only-import-exportability.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public func implementationDetailsUser() {
150150
public struct ClientStruct {
151151
#if !SKIP_ERRORS
152152
public var a: SPIOnlyStruct // expected-error {{cannot use struct 'SPIOnlyStruct' here; 'SPIOnlyImportedLib' was imported for SPI only}}
153-
// expected-error@+1 {{cannot use property 'wrappedValue' here; 'SPIOnlyImportedLib' was imported for SPI only}}
154153
@SPIOnlyPropertyWrapper(42) public var aWrapped: Any // expected-error {{cannot use generic struct 'SPIOnlyPropertyWrapper' as property wrapper here; 'SPIOnlyImportedLib' was imported for SPI only}}
155154
#endif
156155
@PublicPropertyWrapper(SPIOnlyStruct()) public var bWrapped: Any

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ fileprivate import FileprivateLib
8888
// expected-note@-1 2 {{generic struct 'FileprivateImportWrapper' imported as 'fileprivate' from 'FileprivateLib' here}}
8989
// expected-note@-2 2 {{initializer 'init(wrappedValue:)' imported as 'fileprivate' from 'FileprivateLib' here}}
9090
// expected-note@-3 2 {{protocol 'FileprivateImportProto' imported as 'fileprivate' from 'FileprivateLib' here}}
91-
// expected-note@-4 2 {{property 'wrappedValue' imported as 'fileprivate' from 'FileprivateLib' here}}
9291

9392
private import PrivateLib
9493
// expected-note@-1 10 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
@@ -129,7 +128,6 @@ public struct GenericType<T, U> {}
129128

130129
@FileprivateImportWrapper // expected-error {{initializer 'init(wrappedValue:)' is fileprivate and cannot be referenced from an '@inlinable' function}}
131130
// expected-error @-1 {{generic struct 'FileprivateImportWrapper' is fileprivate and cannot be referenced from an '@inlinable' function}}
132-
// expected-error @-2 {{property 'wrappedValue' is fileprivate and cannot be referenced from an '@inlinable' function}}
133131
var wrappedFileprivate: PublicImportType
134132

135133
let _: GenericType<PublicImportType, PublicImportType>
@@ -170,7 +168,6 @@ public struct GenericType<T, U> {}
170168

171169
@FileprivateImportWrapper // expected-error {{initializer 'init(wrappedValue:)' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
172170
// expected-error @-1 {{generic struct 'FileprivateImportWrapper' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
173-
// expected-error @-2 {{property 'wrappedValue' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
174171
var wrappedFileprivate: PublicImportType
175172

176173
let _: GenericType<PublicImportType, PublicImportType>

test/Sema/implementation-only-import-in-decls.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public struct TestInit {
5656

5757
public struct TestPropertyWrapper {
5858
@BadWrapper public var BadProperty: Int // expected-error {{cannot use struct 'BadWrapper' as property wrapper here; 'BADLibrary' has been imported as implementation-only}}
59-
// expected-error@-1 {{cannot use property 'wrappedValue' here; 'BADLibrary' has been imported as implementation-only}}
6059
}
6160

6261
public protocol TestInherited: BadProto {} // expected-error {{cannot use protocol 'BadProto' here; 'BADLibrary' has been imported as implementation-only}}

test/Sema/missing-import-typealias.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public class InheritsFromClazzAlias: ClazzAlias {}
8181
public func takesGeneric<T: ProtoAlias>(_ t: T) {}
8282

8383
public struct HasMembers {
84-
// expected-warning@+3 {{cannot use property 'wrappedValue' here; 'Original' was not imported by this file}}
8584
// expected-warning@+2 {{'WrapperAlias' aliases 'Original.Wrapper' and cannot be used as property wrapper here because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
8685
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
8786
@WrapperAlias public var wrapped: Int

test/Sema/property_wrapper_availability.swift

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,8 @@ struct UnavailableWrapper<T> { // expected-note 8 {{'UnavailableWrapper' has bee
2727
var wrappedValue: T
2828
}
2929

30-
@propertyWrapper
31-
struct WrappedValueUnavailableOnMacOS<T> {
32-
init(wrappedValue: T) { fatalError() }
33-
34-
@available(macOS, unavailable)
35-
var wrappedValue: T { // expected-note 6 {{'wrappedValue' has been explicitly marked unavailable here}}
36-
get { fatalError() }
37-
set { fatalError() }
38-
}
39-
}
40-
41-
@propertyWrapper
42-
struct WrappedValueAvailable51<T> {
43-
init(wrappedValue: T) { fatalError() }
44-
45-
@available(macOS 51, *)
46-
var wrappedValue: T {
47-
get { fatalError() }
48-
set { fatalError() }
49-
}
50-
}
5130

52-
struct AlwaysAvailableStruct { // expected-note 3 {{add @available attribute to enclosing struct}}
31+
struct AlwaysAvailableStruct { // expected-note 2 {{add @available attribute to enclosing struct}}
5332
@AlwaysAvailableWrapper var alwaysAvailableExplicit: S
5433
@AlwaysAvailableWrapper var alwaysAvailableInferred = S()
5534

@@ -61,9 +40,6 @@ struct AlwaysAvailableStruct { // expected-note 3 {{add @available attribute to
6140

6241
@UnavailableWrapper var unavailableExplicit: S // expected-error {{'UnavailableWrapper' is unavailable}}
6342
@UnavailableWrapper var unavailableInferred = S() // expected-error {{'UnavailableWrapper' is unavailable}}
64-
65-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValue: S // expected-error {{'wrappedValue' is unavailable in macOS}}
66-
@WrappedValueAvailable51 var wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
6743
}
6844

6945
@available(macOS 51, *)
@@ -79,9 +55,6 @@ struct Available51Struct {
7955

8056
@UnavailableWrapper var unavailableExplicit: S // expected-error {{'UnavailableWrapper' is unavailable}}
8157
@UnavailableWrapper var unavailableInferred = S() // expected-error {{'UnavailableWrapper' is unavailable}}
82-
83-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValue: S // expected-error {{'wrappedValue' is unavailable in macOS}}
84-
@WrappedValueAvailable51 var wrappedValueAavailable51: S
8558
}
8659

8760
@available(*, unavailable)
@@ -97,9 +70,6 @@ struct UnavailableStruct {
9770

9871
@UnavailableWrapper var unavailableExplicit: S
9972
@UnavailableWrapper var unavailableInferred = S()
100-
101-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValue: S
102-
@WrappedValueAvailable51 var wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
10373
}
10474

10575
@available(macOS, unavailable)
@@ -115,25 +85,18 @@ struct UnavailableOnMacOSStruct {
11585

11686
@UnavailableWrapper var unavailableExplicit: S
11787
@UnavailableWrapper var unavailableInferred = S()
118-
119-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValue: S
120-
@WrappedValueAvailable51 var wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
12188
}
12289

123-
func alwaysAvailableFunc( // expected-note 4 {{add @available attribute to enclosing global function}}
90+
func alwaysAvailableFunc( // expected-note 2 {{add @available attribute to enclosing global function}}
12491
@AlwaysAvailableWrapper _ alwaysAvailable: S,
12592
@Available51Wrapper _ available51: S, // expected-error {{'Available51Wrapper' is only available in macOS 51 or newer}}
12693
@DeprecatedWrapper _ deprecated: S, // expected-warning {{'DeprecatedWrapper' is deprecated}}
12794
@UnavailableWrapper _ unavailable: S, // expected-error {{'UnavailableWrapper' is unavailable}}
128-
@WrappedValueUnavailableOnMacOS _ unavailableWrappedValue: S, // expected-error {{'wrappedValue' is unavailable in macOS}}
129-
@WrappedValueAvailable51 _ wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
13095
) {
13196
@AlwaysAvailableWrapper var alwaysAvailableLocal = S()
13297
@Available51Wrapper var available51Local = S() // expected-error {{'Available51Wrapper' is only available in macOS 51 or newer}}
13398
@DeprecatedWrapper var deprecatedLocal = S() // expected-warning {{'DeprecatedWrapper' is deprecated}}
13499
@UnavailableWrapper var unavailableLocal = S() // expected-error {{'UnavailableWrapper' is unavailable}}
135-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValueLocal = S() // expected-error {{'wrappedValue' is unavailable}}
136-
@WrappedValueAvailable51 var wrappedValueAavailable51 = S() // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
137100
}
138101

139102
@available(macOS 51, *)
@@ -142,15 +105,11 @@ func available51Func(
142105
@Available51Wrapper _ available51: S,
143106
@DeprecatedWrapper _ deprecated: S, // expected-warning {{'DeprecatedWrapper' is deprecated}}
144107
@UnavailableWrapper _ unavailable: S, // expected-error {{'UnavailableWrapper' is unavailable}}
145-
@WrappedValueUnavailableOnMacOS _ unavailableWrappedValue: S, // expected-error {{'wrappedValue' is unavailable in macOS}}
146-
@WrappedValueAvailable51 _ wrappedValueAavailable51: S
147108
) {
148109
@AlwaysAvailableWrapper var alwaysAvailableLocal = S()
149110
@Available51Wrapper var available51Local = S()
150111
@DeprecatedWrapper var deprecatedLocal = S() // expected-warning {{'DeprecatedWrapper' is deprecated}}
151112
@UnavailableWrapper var unavailableLocal = S() // expected-error {{'UnavailableWrapper' is unavailable}}
152-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValueLocal = S() // expected-error {{'wrappedValue' is unavailable}}
153-
@WrappedValueAvailable51 var wrappedValueAavailable51 = S()
154113
}
155114

156115
@available(*, unavailable)
@@ -159,15 +118,11 @@ func unavailableFunc(
159118
@Available51Wrapper _ available51: S,
160119
@DeprecatedWrapper _ deprecated: S,
161120
@UnavailableWrapper _ unavailable: S,
162-
@WrappedValueUnavailableOnMacOS _ unavailableWrappedValue: S,
163-
@WrappedValueAvailable51 _ wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
164121
) {
165122
@AlwaysAvailableWrapper var alwaysAvailableLocal = S()
166123
@Available51Wrapper var available51Local = S()
167124
@DeprecatedWrapper var deprecatedLocal = S()
168125
@UnavailableWrapper var unavailableLocal = S()
169-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValueLocal = S()
170-
@WrappedValueAvailable51 var wrappedValueAavailable51 = S() // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
171126
}
172127

173128
@available(macOS, unavailable)
@@ -176,13 +131,9 @@ func unavailableOnMacOSFunc(
176131
@Available51Wrapper _ available51: S,
177132
@DeprecatedWrapper _ deprecated: S,
178133
@UnavailableWrapper _ unavailable: S,
179-
@WrappedValueUnavailableOnMacOS _ unavailableWrappedValue: S,
180-
@WrappedValueAvailable51 _ wrappedValueAavailable51: S // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
181134
) {
182135
@AlwaysAvailableWrapper var alwaysAvailableLocal = S()
183136
@Available51Wrapper var available51Local = S()
184137
@DeprecatedWrapper var deprecatedLocal = S()
185138
@UnavailableWrapper var unavailableLocal = S()
186-
@WrappedValueUnavailableOnMacOS var unavailableWrappedValueLocal = S()
187-
@WrappedValueAvailable51 var wrappedValueAavailable51 = S() // expected-error {{'wrappedValue' is only available in macOS 51 or newer}}
188139
}

test/Sema/property_wrapper_parameter_invalid.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct Wrapper<T> { // expected-note 3 {{type declared here}}
7777
self.wrappedValue = projectedValue.value
7878
}
7979

80-
// expected-note@+1 {{property 'wrappedValue' is not '@usableFromInline' or public}}
8180
var wrappedValue: T
8281
var projectedValue: Projection<T> { Projection(value: wrappedValue) }
8382
}
@@ -128,7 +127,6 @@ enum E {
128127
// expected-error@+1 {{function cannot be declared public because its parameter uses an internal API wrapper type}}
129128
public func f1(@Wrapper value: Int) {}
130129

131-
// expected-error@+4 {{property 'wrappedValue' is internal and cannot be referenced from an '@inlinable' function}}
132130
// expected-error@+3 {{generic struct 'Wrapper' is internal and cannot be referenced from an '@inlinable' function}}
133131
// expected-error@+2 {{the parameter API wrapper of a '@usableFromInline' function must be '@usableFromInline' or public}}
134132
// expected-error@+1 {{initializer 'init(wrappedValue:)' is internal and cannot be referenced from an '@inlinable' function}}
@@ -157,7 +155,6 @@ public struct PublicWrapper<T> {
157155
// expected-note@+2 2 {{generic struct 'PackageWrapper' is not '@usableFromInline' or public}}
158156
@propertyWrapper
159157
package struct PackageWrapper<T> { // expected-note 3 {{type declared here}}
160-
// expected-note@+1 2 {{property 'wrappedValue' is not '@usableFromInline' or public}}
161158
package var wrappedValue: T
162159

163160
// expected-note@+1 2 {{initializer 'init(wrappedValue:)' is not '@usableFromInline' or public}}
@@ -167,7 +164,6 @@ package struct PackageWrapper<T> { // expected-note 3 {{type declared here}}
167164
// expected-note@+2 2 {{generic struct 'InternalWrapper' is not '@usableFromInline' or public}}
168165
@propertyWrapper
169166
struct InternalWrapper<T> { // expected-note 3 {{type declared here}}
170-
// expected-note@+1 2 {{property 'wrappedValue' is not '@usableFromInline' or public}}
171167
var wrappedValue: T
172168

173169
// expected-note@+1 2 {{initializer 'init(wrappedValue:)' is not '@usableFromInline' or public}}
@@ -204,24 +200,20 @@ public func testComposition2pkg(@PackageWrapper @PublicWrapper value: Int) {}
204200
// Okay because `PackageWrapper` is implementation-detail.
205201
@usableFromInline func testComposition4pkg(@PackageWrapper @PublicWrapper value: Int) {}
206202

207-
// expected-error@+4 {{property 'wrappedValue' is internal and cannot be referenced from an '@inlinable' function}}
208203
// expected-error@+3 {{generic struct 'InternalWrapper' is internal and cannot be referenced from an '@inlinable' function}}
209204
// expected-error@+2 {{the parameter API wrapper of a '@usableFromInline' function must be '@usableFromInline' or public}}
210205
// expected-error@+1 {{initializer 'init(wrappedValue:)' is internal and cannot be referenced from an '@inlinable' function}}
211206
@inlinable func testComposition5(@PublicWrapper @InternalWrapper value: Int) {}
212207

213-
// expected-error@+3 {{property 'wrappedValue' is internal and cannot be referenced from an '@inlinable' function}}
214208
// expected-error@+2 {{generic struct 'InternalWrapper' is internal and cannot be referenced from an '@inlinable' function}}
215209
// expected-error@+1 {{initializer 'init(wrappedValue:)' is internal and cannot be referenced from an '@inlinable' function}}
216210
@inlinable func testComposition6(@InternalWrapper @PublicWrapper value: Int) {}
217211

218-
// expected-error@+4 {{property 'wrappedValue' is package and cannot be referenced from an '@inlinable' function}}
219212
// expected-error@+3 {{generic struct 'PackageWrapper' is package and cannot be referenced from an '@inlinable' function}}
220213
// expected-error@+2 {{the parameter API wrapper of a '@usableFromInline' function must be '@usableFromInline' or public}}
221214
// expected-error@+1 {{initializer 'init(wrappedValue:)' is package and cannot be referenced from an '@inlinable' function}}
222215
@inlinable func testComposition5pkg(@PublicWrapper @PackageWrapper value: Int) {}
223216

224-
// expected-error@+3 {{property 'wrappedValue' is package and cannot be referenced from an '@inlinable' function}}
225217
// expected-error@+2 {{generic struct 'PackageWrapper' is package and cannot be referenced from an '@inlinable' function}}
226218
// expected-error@+1 {{initializer 'init(wrappedValue:)' is package and cannot be referenced from an '@inlinable' function}}
227219
@inlinable func testComposition6pkg(@PackageWrapper @PublicWrapper value: Int) {}

test/Sema/spi-in-decls.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct IntLike: ExpressibleByIntegerLiteral, Equatable { // expected-note
3636
@_spi(X)
3737
@propertyWrapper
3838
public struct BadWrapper { // expected-note {{struct declared here}}
39-
public var wrappedValue: Int // expected-note {{property declared here}}
39+
public var wrappedValue: Int
4040
public init(wrappedValue: Int) {
4141
self.wrappedValue = wrappedValue
4242
}
@@ -87,7 +87,6 @@ public struct TestInit {
8787

8888
public struct TestPropertyWrapper {
8989
@BadWrapper public var BadProperty: Int // expected-error {{cannot use struct 'BadWrapper' as property wrapper here; it is SPI}}
90-
// expected-error@-1 {{cannot use property 'wrappedValue' here; it is SPI}}
9190
}
9291

9392
public protocol TestInherited: BadProto {} // expected-error {{cannot use protocol 'BadProto' here; it is SPI}}

test/decl/var/property_wrappers.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ struct Observable<Value> {
961961
}
962962

963963
@available(*, unavailable, message: "must be in a class")
964-
var wrappedValue: Value { // expected-note 2{{'wrappedValue' has been explicitly marked unavailable here}}
964+
var wrappedValue: Value { // expected-note{{'wrappedValue' has been explicitly marked unavailable here}}
965965
get { fatalError("called wrappedValue getter") }
966966
set { fatalError("called wrappedValue setter") }
967967
}
@@ -985,13 +985,6 @@ struct MyObservedValueType {
985985
var observedProperty = 17
986986
}
987987

988-
func takesObservable(@Observable _ observable: Int) {} // expected-error{{'wrappedValue' is unavailable: must be in a class}}
989-
990-
class MyObservedClass {
991-
@Observable
992-
var observedProperty = 17
993-
}
994-
995988
// ---------------------------------------------------------------------------
996989
// Miscellaneous bugs
997990
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)