Files
swift-mirror/test/Generics/inverse_protocols.swift
Kavon Farvardin 0420310623 NCGenerics: it's no longer "experimental"
resolves rdar://127701059
2024-05-08 10:49:12 -07:00

31 lines
796 B
Swift

// RUN: %target-typecheck-verify-swift
protocol Eq: ~Copyable {
func same(as: borrowing Self) -> Bool
func different(from: borrowing Self) -> Bool
}
extension Eq where Self: ~Copyable {
func different(from other: borrowing Self) -> Bool { !same(as: other) }
}
struct File: ~Copyable, Eq {
let fd: Int = 0
deinit {}
func same(as other: borrowing Self) -> Bool {
return fd == other.fd
}
}
func check<T: ~Copyable>(_ a: T, _ b: borrowing T) -> Bool where T: Eq {
// expected-error@-1 {{parameter of noncopyable type 'T' must specify ownership}}
// expected-note@-2 {{add 'borrowing' for an immutable reference}}
// expected-note@-3 {{add 'inout' for a mutable reference}}
// expected-note@-4 {{add 'consuming' to take the value from the caller}}
return a.same(as: b)
}