Skip to content

Commit 7a11b43

Browse files
Merge pull request swiftlang#59271 from AnthonyLatsis/sr-2063
Add regression tests to close several fixed issues
2 parents 5b77b32 + 94796e0 commit 7a11b43

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

test/Constraints/operator.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,13 @@ postfix operator ^^^
296296
postfix func ^^^ (lhs: Int) -> Int! { 0 }
297297

298298
let x: Int = 1^^^
299+
300+
// https://github.com/apple/swift/issues/44672 - DiagnosticsQoI
301+
do {
302+
enum TestEnum: Int {
303+
case First, Second
304+
}
305+
306+
let number = 1
307+
let test = true || number == .First.rawValue // expected-error {{type 'Int' has no member 'First'}}
308+
}

test/Generics/unbound.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,34 @@ func nested(_: OuterStruct.InnerStruct<Int>) {}
106106

107107
func nested(_: OuterStruct<Int>.InnerStruct) {}
108108
// expected-error@-1 {{reference to generic type 'OuterStruct<Int>.InnerStruct' requires arguments in <...>}}
109+
110+
111+
func assertExactType<T>(of _: T, is _: T.Type) {}
112+
113+
// https://github.com/apple/swift/issues/51217
114+
protocol P {
115+
associatedtype A
116+
associatedtype B
117+
}
118+
do {
119+
struct Concrete: P {
120+
typealias A = Int
121+
typealias B = Bool
122+
}
123+
struct Generic<A, B>: P {}
124+
125+
struct BinderGenericParams1<T1: P, T2: P>
126+
where T1.A == T2.A, T1.B == T2.B {
127+
static func bind(_: T1, _: T2) -> T2 {}
128+
}
129+
struct BinderGenericParams2 {
130+
static func bind<T1: P, T2: P>(_: T1, _: T2) -> T2
131+
where T1.A == T2.A, T1.B == T2.B {}
132+
}
133+
134+
let x1 = BinderGenericParams1.bind(Concrete(), Generic())
135+
let x2 = BinderGenericParams2.bind(Concrete(), Generic())
136+
137+
assertExactType(of: x1, is: Generic<Int, Bool>.self)
138+
assertExactType(of: x2, is: Generic<Int, Bool>.self)
139+
}

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,27 @@ struct S40<E: Equatable>: P40c {
684684
typealias B = Self
685685
}
686686

687+
protocol P41a {
688+
associatedtype A
689+
associatedtype B
690+
691+
func bar(_: B) -> A?
692+
}
693+
protocol P42b: P41a {
694+
associatedtype A
695+
associatedtype B
696+
697+
func foo(_: A, _: B)
698+
}
699+
extension P42b {
700+
func bar(_: B) -> A? {}
701+
}
702+
do {
703+
class Conformer: P42b {
704+
func foo(_: Bool, _: String) {}
705+
}
706+
}
707+
687708
// Fails to find the fixed type witness B == FIXME_S1<A>.
688709
protocol FIXME_P1a {
689710
associatedtype A: Equatable = Never // expected-note {{protocol requires nested type 'A'}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Box<T> {}
4+
5+
infix operator =*=
6+
protocol P1 {
7+
associatedtype A
8+
static func =*= (x: Self, y: Box<A>)
9+
}
10+
class C1<A>: P1 {
11+
static func =*= (x: C1, y: Box<A>) {}
12+
}

test/decl/protocol/req/associated_type_inference_proto_ext.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-typecheck-verify-swift
22

3+
func assertEqualTypes<T>(_: T.Type, _: T.Type) {}
4+
35
struct Pair<A, B> {
46
var a: A
57
var b: B
@@ -28,3 +30,33 @@ extension Pair: Collection where A == B {
2830
return i + 1
2931
}
3032
}
33+
34+
// https://github.com/apple/swift/issues/52024
35+
protocol VectorBase : RandomAccessCollection where Index == Int, Element == Elle {
36+
associatedtype Elle
37+
38+
var data: Array<Elle> { get set }
39+
init(data: Array<Elle>)
40+
}
41+
42+
protocol Vector: VectorBase {}
43+
extension Vector where Elle: FloatingPoint {
44+
// RandomAccessCollection
45+
var indices: Range<Int> { get {} }
46+
var startIndex: Int { get {} }
47+
var endIndex: Int { get {} }
48+
49+
// MutableCollection
50+
subscript(i: Index) -> Elle {
51+
get {} set {}
52+
}
53+
}
54+
55+
do {
56+
struct VectorF: Vector {
57+
var data: Array<Float>
58+
init(data: Array<Float>) {}
59+
}
60+
61+
assertEqualTypes(VectorF.Elle.self, Float.self)
62+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %swift-ide-test -code-completion -code-completion-token=COMPLETE -source-filename %s
2+
3+
extension Result {
4+
public init(_ value: Success?) {
5+
self = value.map(#^COMPLETE^#)
6+
}
7+
}
8+
9+
public func materialize<T>(_ f: T) {}

0 commit comments

Comments
 (0)