Files
swift-mirror/test/decl/protocol/req/deprecated.swift
Holly Borla 005b45c1cc [Sema] Diagnose deprecated default implementations in the witness checker.
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.
2024-06-10 07:10:38 -07:00

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 {}