Files
swift-mirror/test/Generics/inverse_protocols_errors.swift
Kavon Farvardin 85340ea148 [HasNoncopyableAnnotationRequest] handle where
Adds rudiementary support for searching `where` clauses for `~Copyable`
constraints, but the implementation is known to have flaws.
2023-10-18 13:52:14 -07:00

50 lines
1.7 KiB
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-feature NoncopyableGenerics
// REQUIRES: asserts
protocol RegularProto {}
protocol NCProto: ~Copyable, RegularProto {
// expected-warning@-1 {{protocol 'NCProto' should be declared to refine 'Copyable' due to a same-type constraint on 'Self'}}
func checkIfCopyableSelf(_ s: Self)
}
protocol Hello: ~Copyable {
func greet(_ s: Self)
// expected-error@-1 {{noncopyable parameter must specify its 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}}
func salute(_ s: borrowing Self)
}
struct RegularStruct: Hello {
func greet(_ s: Self) {}
func salute(_ s: Self) {}
}
struct NCThinger<T: ~Copyable>: ~Copyable, Hello {
let fd: Int = 0
deinit {}
func greet(_ f: Self) {}
// expected-error@-1 {{noncopyable parameter must specify its 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}}
func salute(_ s: borrowing Self) {}
func setThinger(_ t: T) {}
// expected-error@-1 {{noncopyable parameter must specify its 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}}
}
struct ExtraNoncopyStruct: ~Copyable, ~Copyable {}
// expected-error@-1 {{duplicate inverse constraint}}
// expected-note@-2 {{previous inverse constraint here}}
protocol ExtraNoncopyProto: ~Copyable, ~Copyable {}