Skip to content

Commit 6254588

Browse files
committed
Sema: Add a test that passes with -enable-experimental-associated-type-inference
1 parent af070cb commit 6254588

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: not %target-typecheck-verify-swift
3+
4+
public protocol FakeCopyable {}
5+
6+
extension Int: FakeCopyable {}
7+
8+
// Remove both 'FakeCopyable' requirements below and
9+
// inference for Element in Hello succeeds.
10+
11+
public protocol MyIteratorProtocol<Element> {
12+
associatedtype Element : FakeCopyable
13+
14+
mutating func next() -> Element?
15+
}
16+
17+
public protocol MySequence<Element> {
18+
associatedtype Element : FakeCopyable
19+
20+
associatedtype Iterator: MyIteratorProtocol where Iterator.Element == Element
21+
22+
__consuming func makeIterator() -> Iterator
23+
24+
func _customContainsEquatableElement(
25+
_ element: Element
26+
) -> Bool?
27+
}
28+
29+
extension MySequence {
30+
@usableFromInline
31+
func _customContainsEquatableElement(
32+
_ element: Iterator.Element
33+
) -> Bool? { return nil }
34+
}
35+
36+
extension MySequence where Self.Iterator == Self {
37+
@inlinable
38+
public __consuming func makeIterator() -> Self {
39+
return self
40+
}
41+
}
42+
43+
// ------------
44+
45+
internal struct Hello {}
46+
47+
extension Hello: MySequence, MyIteratorProtocol {
48+
// Inferred:
49+
// typealias Element = Int
50+
51+
internal mutating func next() -> Int? {
52+
return nil
53+
}
54+
}

0 commit comments

Comments
 (0)