Files
swift-mirror/test/Generics/superclass_requirement_and_objc_existential.swift
Slava Pestov 70c9f8a47e RequirementMachine: Leave behind conflicting requirements in the minimized signature
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.
2024-02-15 14:32:31 -05:00

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'}}