Files
swift-mirror/test/Sema/conformance_availability_implied_multifile.swift
Slava Pestov de1d2905fd Sema: Relax diagnosis of implied marker protocol conformances with mismatched availability
This logic was introduced in https://github.com/swiftlang/swift/pull/75135.
The intent was to prevent an implied conformance from overriding an
existing unavailable one, for example in the case of Sendable. Let's
relax this check a bit to only diagnose if the mismatch is in the
unconditional availability, and not OS version.

Fixes rdar://142873265.
2025-06-17 14:43:03 -04:00

49 lines
1.4 KiB
Swift

// RUN: %target-swift-frontend -typecheck -verify %s %S/Inputs/conformance_availability_implied_other.swift -swift-version 6
// RUN: %target-swift-frontend -typecheck -verify %S/Inputs/conformance_availability_implied_other.swift %s -swift-version 6
// REQUIRES: OS=macosx
protocol Base {
func f()
}
func takesBase<T: Base>(_: T.Type) {}
protocol Derived1: Base {}
protocol Derived2: Base {}
// Verify that the implied conformance is macOS 100:
struct Conformer1 {}
@available(macOS 100, *)
extension Conformer1: Derived1 {
func f() {} // okay!
}
// Note that Conformer1: Derived2 is in the other file
func check1() {
// expected-note@-1 {{add '@available' attribute to enclosing global function}}
takesBase(Conformer1.self)
// expected-error@-1 {{conformance of 'Conformer1' to 'Base' is only available in macOS 100 or newer}}
// expected-note@-2 {{add 'if #available' version check}}
}
// Verify that the implied conformance is macOS 200:
// FIXME: This appears to be unsound!
struct Conformer2 {}
@available(macOS 200, *)
extension Conformer2: Derived2 {
func f() {}
}
// Note that Conformer2: Derived1 is in the other file
func check2() {
// expected-note@-1 {{add '@available' attribute to enclosing global function}}
takesBase(Conformer2.self)
// expected-error@-1 {{conformance of 'Conformer2' to 'Base' is only available in macOS 200 or newer}}
// expected-note@-2 {{add 'if #available' version check}}
}