Files
swift-mirror/test/Generics/inverse_protocols_errors.swift
Kavon Farvardin 6f95203dfd Sema: introduce SuppressedAssociatedTypesWithDefaults
This is similar to SuppressedAssociatedTypes, but infers
default requirements when primary associated types of
protocols are suppressed. This defaulting for the primary
associated types happens in extensions of the protocol,
along with generic parameters, whenever a source-written
requirement states a conformance requirement for the protocol.

Thus, the current scheme for this defaulting is a simplistic,
driven by source-written requirements, rather than facts
that are inferred while building generic signatures.

Defaults are not expanded for infinitely many associated types.

rdar://135168163
2025-12-02 18:00:03 -08:00

44 lines
1.5 KiB
Swift

// RUN: %target-typecheck-verify-swift
protocol RegularProto {}
protocol NCProto: RegularProto
where Self: ~Copyable { // expected-error{{'Self' required to be 'Copyable' but is marked with '~Copyable'}}
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}}
}