mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
If a protocol provides a deprecated default implementation for a requirement that is not deprecated, the compiler should emit a warning so the programmer can provide an explicit implementation of the requirement. This is helpful for staging in new protocol requirements that should be implemented in conforming types.
61 lines
1.6 KiB
Swift
61 lines
1.6 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
protocol DeprecatedRequirement {
|
|
@available(*, deprecated)
|
|
func f()
|
|
}
|
|
|
|
extension DeprecatedRequirement {
|
|
@available(*, deprecated)
|
|
func f() {}
|
|
}
|
|
|
|
// No warning if both the requirement and the default implementation are deprecated
|
|
struct S1: DeprecatedRequirement {}
|
|
|
|
protocol DeprecatedDefault {
|
|
func f() // expected-note {{requirement 'f()' declared here}}
|
|
}
|
|
|
|
extension DeprecatedDefault {
|
|
@available(*, deprecated)
|
|
func f() {} // expected-note {{'f()' declared here}}
|
|
}
|
|
|
|
// expected-warning@+1 {{deprecated default implementation is used to satisfy instance method 'f()' required by protocol 'DeprecatedDefault'}}
|
|
struct S2: DeprecatedDefault {}
|
|
|
|
// No warning if the conformance itself is deprecated
|
|
@available(*, deprecated)
|
|
struct S3: DeprecatedDefault {
|
|
}
|
|
|
|
struct S4: DeprecatedDefault {
|
|
func f() {}
|
|
}
|
|
|
|
struct S5 {}
|
|
|
|
// No warning if the conformance itself is deprecated
|
|
@available(*, deprecated)
|
|
extension S5: DeprecatedDefault {}
|
|
|
|
@available(*, deprecated)
|
|
enum UnavailableEnum {
|
|
struct Nested: DeprecatedDefault {}
|
|
}
|
|
|
|
// Include message string from @available attribute if provided
|
|
protocol DeprecatedDefaultWithMessage {
|
|
func f() // expected-note {{requirement 'f()' declared here}}
|
|
}
|
|
|
|
extension DeprecatedDefaultWithMessage {
|
|
@available(*, deprecated, message: "write it yourself")
|
|
func f() {} // expected-note {{'f()' declared here}}
|
|
}
|
|
|
|
|
|
// expected-warning@+1 {{deprecated default implementation is used to satisfy instance method 'f()' required by protocol 'DeprecatedDefaultWithMessage': write it yourself}}
|
|
struct S6: DeprecatedDefaultWithMessage {}
|