Files
swift-mirror/test/Generics/rdar94150249.swift
Slava Pestov 9695b1957a RequirementMachine: Concrete contraction needs to substitute the parent type of a subject type sometimes
If you have generic parameters <T, U> and requirements of the form:

- T : P
- T == ConcreteType<U>
- T.[P]U : SomeClass
- T.[P]U : SomeProto

And furthermore SomeClass does not conform to SomeProto, we can't leave
`T.[P]U : SomeClass` unsubstituted; we still have to replace `T` with
`ConcreteType<U>` to transform the latter two requirements into:

- U : SomeClass
- U : SomeProto

"Concrete contraction" is easily the hackiest part of the Requirement
Machine; I need to come up with a more principled solution for the
problem that it solves sooner or later.

Fixes rdar://problem/94150249.
2022-06-08 00:40:30 -04:00

30 lines
634 B
Swift

// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
protocol P1 {
associatedtype Value
}
protocol P2 {
associatedtype Value
}
class G<Value> : P2 {}
protocol P3 {}
class C {}
extension P1 where Value: P2 {
typealias Element = Value.Value
// Make sure we can resolve 'Element' to 'V' on the left hand side of 'Element: P3'.
// CHECK-LABEL: .P1 extension.set()@
// CHECK-NEXT: Generic signature: <Self, V where Self : P1, V : C, V : P3, Self.[P1]Value == G<V>>
func set<V>() where Element: P3 & C, Value == G<V> {
takeP3(V.self)
}
}
func takeP3<T : P3>(_: T.Type) {}