mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Requirement lowering only expects that it won't see two requirements of the same kind (except for conformance requirements). So only mark those as conflicting. This addresses a crash-on-invalid and improves diagnostics for move-only generics, because a conflict won't drop the copyability of a generic parameter and expose a move-only-naive user to confusing error messages. Fixes #61031. Fixes #63997. Fixes rdar://problem/111991454.
40 lines
1.5 KiB
Swift
40 lines
1.5 KiB
Swift
// RUN: %target-typecheck-verify-swift -disable-objc-attr-requires-foundation-module
|
|
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-objc-attr-requires-foundation-module 2>&1 | %FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
class C {}
|
|
@objc protocol P1 {}
|
|
protocol P2 {}
|
|
protocol P3 : AnyObject {}
|
|
|
|
protocol Q {
|
|
associatedtype A
|
|
}
|
|
|
|
/// This is allowed, even though it's not fully sound.
|
|
|
|
// CHECK-LABEL: .f1@
|
|
// CHECK-NEXT: Generic signature: <T where T : Q, T.[Q]A == any C & P1>
|
|
func f1<T : Q>(_: T) where T.A : C, T.A == any (C & P1) {}
|
|
|
|
/// These are not allowed.
|
|
|
|
// CHECK-LABEL: .f2@
|
|
// CHECK-NEXT: Generic signature: <T where T : Q, T.[Q]A : C, T.[Q]A == any P1>
|
|
func f2<T : Q>(_: T) where T.A : C, T.A == any P1 {}
|
|
// expected-error@-1 {{no type for 'T.A' can satisfy both 'T.A : C' and 'T.A == any P1'}}
|
|
|
|
// CHECK-LABEL: .f3@
|
|
// CHECK-NEXT: Generic signature: <T where T : Q, T.[Q]A : C, T.[Q]A == any C & P2>
|
|
func f3<T : Q>(_: T) where T.A : C, T.A == any (C & P2) {}
|
|
// expected-error@-1 {{no type for 'T.A' can satisfy both 'T.A : C' and 'T.A == any C & P2'}}
|
|
// expected-error@-2 {{no type for 'T.A' can satisfy both 'T.A : _NativeClass' and 'T.A == any C & P2'}}
|
|
|
|
// CHECK-LABEL: .f4@
|
|
// CHECK-NEXT: Generic signature: <T where T : Q, T.[Q]A : C, T.[Q]A == any C & P3>
|
|
func f4<T : Q>(_: T) where T.A : C, T.A == any (C & P3) {}
|
|
// expected-error@-1 {{no type for 'T.A' can satisfy both 'T.A : C' and 'T.A == any C & P3'}}
|
|
// expected-error@-2 {{no type for 'T.A' can satisfy both 'T.A : _NativeClass' and 'T.A == any C & P3'}}
|
|
|