Files
swift-mirror/test/Availability/Inputs/reparenting.swift
Kavon Farvardin 3bf9cb5cd7 Availability: handle reparented protocols
Since reparentable protocols can have less availability
than the protocols inheriting from it, we need to first
loosen availability checking inheritance clauses to allow
for the statement of retroactive refinement.

Then, we need to tighten it in other places in terms of
expression checking, because we now cannot refer to
members of a generic type that originate from an unavailable
ancestor of a protocol to which the value conforms. Previously
it was not possible for that to be the case, so no checking
was performed.
2026-02-15 19:43:31 -08:00

41 lines
782 B
Swift

#if IncludeNewProto
@available(macOS 12, *)
@reparentable public protocol NewProto {
associatedtype Thing: Equatable
func new() -> Thing
}
@available(macOS 12, *)
extension Existing: @reparented NewProto where Thing == String {
public func new() -> Thing { return "defaulted Existing.new" }
}
public protocol Existing: NewProto {
associatedtype Thing: Equatable = String
func existing() -> Thing
}
#else
public protocol Existing {
associatedtype Thing: Equatable = String
func existing() -> Thing
}
#endif
public protocol Derived: Existing {
func derived() -> Thing
}
public func libraryFunc(_ s: some Derived) {
print("libraryFunc start")
print(s.derived())
print(s.existing())
#if IncludeNewProto
print(s.new())
#endif
print("libraryFunc end")
}