Files
swift-mirror/test/Generics/inverse_protocols_errors.swift
Kavon Farvardin bbbf4e7d43 [Sema] drop half-baked redundancy checking for now
We already don't diagnose all redundant requirements. Because inverses
can be written in both inheritance and where clauses, but they're not
treated uniformly in the implementation, it's a bit annoying to try and
account for the redundancies in both places; `checkInheritanceClause`
will go over the same "requirements" that we'll also check again in
`swift::rewriting::expandDefaultRequirements`.
2023-10-28 15:31:44 -07:00

44 lines
1.6 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 {{parameter of noncopyable type 'Self' 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}}
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 {{parameter of noncopyable type 'NCThinger<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}}
func salute(_ s: borrowing Self) {}
func setThinger(_ t: T) {}
// 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}}
}