Skip to content

Commit 569a73e

Browse files
committed
Sema: Add a test for an older failure with -enable-experimental-associated-type-inference
1 parent 6254588 commit 569a73e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift
3+
4+
public typealias A = UInt32
5+
6+
public protocol P1: Numeric, Strideable, CustomStringConvertible
7+
where Magnitude == B.Magnitude,
8+
IntegerLiteralType == B.Magnitude,
9+
Stride == B.Stride {
10+
associatedtype B: BinaryInteger
11+
init(_ b: B)
12+
init(integerLiteral value: B)
13+
14+
var rawIndex: B { get set }
15+
16+
var magnitude: B.Magnitude { get }
17+
}
18+
19+
public extension P1 {
20+
init(integerLiteral value: B) {
21+
self.init(value)
22+
}
23+
24+
init<T>(_ value: T) where T: BinaryInteger {
25+
self.init(B(value))
26+
}
27+
28+
init?<T>(exactly source: T) where T: BinaryInteger {
29+
if let index = B(exactly: source) {
30+
self.init(index)
31+
} else {
32+
return nil
33+
}
34+
}
35+
36+
var magnitude: Self.Magnitude {
37+
rawIndex.magnitude
38+
}
39+
40+
var description: String {
41+
rawIndex.description
42+
}
43+
44+
func distance(to other: Self) -> Stride {
45+
rawIndex.distance(to: other.rawIndex)
46+
}
47+
48+
func advanced(by n: Stride) -> Self {
49+
Self(rawIndex.advanced(by: n))
50+
}
51+
52+
static func == (lhs: Self, rhs: Self) -> Bool {
53+
lhs.rawIndex == rhs.rawIndex
54+
}
55+
56+
static func == <B: BinaryInteger>(lhs: Self, rhs: B) -> Bool {
57+
lhs.rawIndex == rhs
58+
}
59+
60+
static func == <B: BinaryInteger>(lhs: B, rhs: Self) -> Bool {
61+
lhs == rhs.rawIndex
62+
}
63+
64+
static func < (lhs: Self, rhs: Self) -> Bool {
65+
lhs.rawIndex < rhs.rawIndex
66+
}
67+
68+
static func + (lhs: Self, rhs: Self) -> Self {
69+
Self(lhs.rawIndex + rhs.rawIndex)
70+
}
71+
72+
static func - (lhs: Self, rhs: Self) -> Self {
73+
Self(lhs.rawIndex - rhs.rawIndex)
74+
}
75+
76+
static func * (lhs: Self, rhs: Self) -> Self {
77+
Self(lhs.rawIndex * rhs.rawIndex)
78+
}
79+
80+
static func *= (lhs: inout Self, rhs: Self) {
81+
lhs.rawIndex *= rhs.rawIndex
82+
}
83+
}
84+
85+
public protocol P2: P1 where B == A {
86+
init(b: B)
87+
var b: B { get set }
88+
}
89+
90+
public extension P2 {
91+
init(_ b: B) {
92+
self.init(b: b)
93+
}
94+
95+
var rawIndex: A {
96+
get {
97+
b
98+
}
99+
set(newIndex) {
100+
b = newIndex
101+
}
102+
}
103+
}
104+
105+
struct S {
106+
var b: A
107+
}
108+
109+
extension S: P2 {}
110+

0 commit comments

Comments
 (0)