Skip to content

Commit b852f94

Browse files
authored
Merge pull request #79910 from slavapestov/test-cases-from-failed-attempts
Add a couple of regression tests
2 parents 7f1792a + 1a38309 commit b852f94

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
import CoreGraphics
6+
7+
/////////////
8+
9+
struct G<T> { // expected-note {{arguments to generic parameter 'T' ('CGFloat?' and 'CGFloat') are expected to be equal}}
10+
var t: T
11+
}
12+
13+
func foo1(x: (x: Int, y: Int)?, y: (Int, Int)) -> G<(x: Int, y: Int)> {
14+
let g = G(t: x ?? y)
15+
return g
16+
}
17+
18+
func foo2(x: (Int, Int)?, y: (x: Int, y: Int)) -> G<(Int, Int)> {
19+
let g = G(t: x ?? y)
20+
return g
21+
}
22+
23+
func foo3(x: (@convention(block) () -> ())?, y: @escaping () -> ()) -> G<@convention(block) () -> ()> {
24+
let g = G(t: x ?? y)
25+
return g
26+
}
27+
28+
func foo4(x: (() -> ())?, y: @escaping @convention(block) () -> ()) -> G<() -> ()> {
29+
let g = G(t: x ?? y)
30+
return g
31+
}
32+
33+
func foo5(x: CGFloat?, y: Double) -> G<CGFloat> {
34+
let g = G(t: x ?? y)
35+
// FIXME
36+
return g // expected-error {{cannot convert return expression of type 'G<CGFloat?>' to return type 'G<CGFloat>'}}
37+
}
38+
39+
func foo6(x: Double?, y: CGFloat) -> G<Double> {
40+
let g = G(t: x ?? y)
41+
return g
42+
}
43+
44+
/////////////
45+
46+
func id<T>(_: T) -> T {}
47+
48+
func bar1(x: (x: Int, y: Int)) {
49+
func f(_: (Int, Int)) {}
50+
f(id(x))
51+
}
52+
53+
func bar2(x: (Int, Int)) {
54+
func f(_: (x: Int, y: Int)) {}
55+
f(id(x))
56+
}
57+
58+
func bar3(x: @escaping () -> ()) {
59+
func f(_: @escaping @convention(block) () -> ()) {}
60+
// FIXME
61+
f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('@convention(block) () -> ()' vs. '() -> ()')}}
62+
}
63+
64+
func bar4(x: @escaping @convention(block) () -> ()) {
65+
func f(_: @escaping () -> ()) {}
66+
// FIXME
67+
f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('() -> ()' vs. '@convention(block) () -> ()')}}
68+
}
69+
70+
func bar5(x: Double) {
71+
func f(_: CGFloat) {}
72+
f(id(x))
73+
}
74+
75+
func bar6(x: CGFloat) {
76+
func f(_: Double) {}
77+
f(id(x))
78+
}
79+
80+
/////////////
81+
82+
func unwrap<T>(_: T?) -> T {}
83+
84+
func baz1(x: (x: Int, y: Int)?) {
85+
func f(_: (Int, Int)) {}
86+
f(unwrap(x))
87+
}
88+
89+
func baz2(x: (Int, Int)?) {
90+
func f(_: (x: Int, y: Int)) {}
91+
f(unwrap(x))
92+
}
93+
94+
func baz3(x: (() -> ())?) {
95+
func f(_: @escaping @convention(block) () -> ()) {}
96+
f(unwrap(x))
97+
}
98+
99+
func baz4(x: (@convention(block) () -> ())?) {
100+
func f(_: @escaping () -> ()) {}
101+
f(unwrap(x))
102+
}
103+
104+
func baz5(x: Double?) {
105+
func f(_: CGFloat) {}
106+
f(unwrap(x))
107+
}
108+
109+
func baz6(x: CGFloat?) {
110+
func f(_: Double) {}
111+
f(unwrap(x))
112+
}
113+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-typecheck-verify-swift -solver-scope-threshold=2000
2+
3+
// We don't use anything from Foundation below, but Foundation adds a
4+
// large number of == overloads. Import it if we can, because it makes
5+
// the problem instance harder.
6+
#if canImport(Foundation)
7+
import Foundation
8+
#endif
9+
10+
struct Graph {
11+
func nodeWithReference(_: Int) -> Node? { fatalError() }
12+
}
13+
14+
struct DocumentationContext {
15+
func parents(of: Int) -> [Int] { fatalError() }
16+
var topicGraph: Graph
17+
}
18+
19+
struct Node {
20+
var reference: Int
21+
var kind: Kind
22+
23+
enum Kind {
24+
case tutorialTableOfContents
25+
case chapter
26+
case volume
27+
}
28+
}
29+
30+
func analyze(_ node: Node, context: DocumentationContext) {
31+
_ = context.parents(of: node.reference)
32+
.compactMap({ context.topicGraph.nodeWithReference($0) })
33+
.first(where: { $0.kind == .tutorialTableOfContents || $0.kind == .chapter || $0.kind == .volume })
34+
}
35+

0 commit comments

Comments
 (0)