Skip to content

Commit b84d70b

Browse files
committed
[Tests] NFC: Add a few test-cases to ensure that some conjunctions are solved early
1 parent fda7530 commit b84d70b

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %target-typecheck-verify-swift -debug-constraints -disable-availability-checking 2>%t.err
2+
// RUN: %FileCheck %s < %t.err
3+
4+
protocol P<Output> {
5+
associatedtype Output
6+
}
7+
8+
struct S<Output> : P {
9+
init(_: Output) {}
10+
}
11+
12+
@resultBuilder
13+
struct Builder {
14+
static func buildExpression<T>(_ e: T) -> T { e }
15+
16+
static func buildBlock<T1>(_ t1: T1) -> some P<T1> {
17+
return S(t1)
18+
}
19+
20+
static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> some P<(T1, T2)> {
21+
return S((t1, t2))
22+
}
23+
24+
static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3) -> some P<(T1, T2, T3)> {
25+
return S((t1, t2, t3))
26+
}
27+
28+
static func buildOptional<T>(_ value: T?) -> T? { return value }
29+
}
30+
31+
do {
32+
func test<T, U>(_: T, @Builder _: () -> some P<U>) {}
33+
34+
// CHECK: ---Initial constraints for the given expression---
35+
// CHECK: (integer_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}}
36+
// CHECK: (attempting type variable [[CLOSURE:\$T[0-9]+]] := () -> {{.*}}
37+
// CHECK-NOT: (attempting type variable [[LITERAL_VAR]] := {{.*}}
38+
// CHECK: (attempting conjunction element pattern binding element @ 0
39+
// CHECK: (applying conjunction result to outer context
40+
// CHECK: (attempting type variable [[LITERAL_VAR]] := Int
41+
test(42) {
42+
1
43+
""
44+
}
45+
}
46+
47+
do {
48+
func test<T, U>(_: T, @Builder _: (T) -> some P<U>) {}
49+
50+
// CHECK: ---Initial constraints for the given expression---
51+
// CHECK: (integer_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}}
52+
// CHECK: (attempting type variable [[LITERAL_VAR]] := Int
53+
// CHECK: (attempting conjunction element pattern binding element @ 0
54+
test(42) { v in
55+
v
56+
""
57+
}
58+
}
59+
60+
do {
61+
func test<T: BinaryInteger, U>(@Builder _: (Bool) -> some P<T>, transform: (T?) -> U) {}
62+
63+
// CHECK: ---Initial constraints for the given expression---
64+
// CHECK: (attempting type variable {{.*}} := () -> {{.*}}
65+
// CHECK: (attempting conjunction element pattern binding element @ 0 :
66+
// CHECK-NEXT: (pattern_named 'x')
67+
// CHECK: (attempting conjunction element syntactic element
68+
// CHECK-NEXT: (call_expr {{.*}}
69+
// CHECK: (attempting type variable {{.*}} := (Bool) -> {{.*}}
70+
// CHECK: (attempting conjunction element pattern binding element @ 0
71+
// CHECK: (pattern_named implicit '$__builder{{.*}}')
72+
// CHECK: (applying conjunction result to outer context
73+
// CHECK: (attempting type variable {{.*}} := (Int?) -> {{.*}}
74+
// CHECK: (attempting disjunction choice {{.*}} bound to decl {{.*}}.Int.init(_:)
75+
let _ = {
76+
let x = 42
77+
test { cond in
78+
x
79+
} transform: { v in
80+
Int(v ?? 0)
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)