Skip to content

Commit c931c1f

Browse files
committed
Add tests
1 parent 92c83c1 commit c931c1f

3 files changed

+89
-0
lines changed

tests/neg/tupled-function-instances.scala

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,57 @@ object Test {
2626
the[TupledFunction[given (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23), R]] // error
2727
the[TupledFunction[given (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), R]] // error
2828
the[TupledFunction[given (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25), R]] // error
29+
30+
the[TupledFunction[erased 1 => R, Tuple1[1], R]] // error
31+
the[TupledFunction[erased (1, 2) => R, (1, 2), R]] // error
32+
the[TupledFunction[erased (1, 2, 3) => R, (1, 2, 3), R]] // error
33+
the[TupledFunction[erased (1, 2, 3, 4) => R, (1, 2, 3, 4), R]] // error
34+
the[TupledFunction[erased (1, 2, 3, 4, 5) => R, (1, 2, 3, 4, 5), R]] // error
35+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6) => R, (1, 2, 3, 4, 5, 6), R]] // error
36+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7) => R, (1, 2, 3, 4, 5, 6, 7), R]] // error
37+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8) => R, (1, 2, 3, 4, 5, 6, 7, 8), R]] // error
38+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9), R]] // error
39+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), R]] // error
40+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), R]] // error
41+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), R]] // error
42+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), R]] // error
43+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), R]] // error
44+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), R]] // error
45+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), R]] // error
46+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), R]] // error
47+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), R]] // error
48+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19), R]] // error
49+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), R]] // error
50+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), R]] // error
51+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), R]] // error
52+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23), R]] // error
53+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), R]] // error
54+
the[TupledFunction[erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25), R]] // error
55+
56+
the[TupledFunction[given erased 1 => R, Tuple1[1], R]] // error
57+
the[TupledFunction[given erased (1, 2) => R, (1, 2), R]] // error
58+
the[TupledFunction[given erased (1, 2, 3) => R, (1, 2, 3), R]] // error
59+
the[TupledFunction[given erased (1, 2, 3, 4) => R, (1, 2, 3, 4), R]] // error
60+
the[TupledFunction[given erased (1, 2, 3, 4, 5) => R, (1, 2, 3, 4, 5), R]] // error
61+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6) => R, (1, 2, 3, 4, 5, 6), R]] // error
62+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7) => R, (1, 2, 3, 4, 5, 6, 7), R]] // error
63+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8) => R, (1, 2, 3, 4, 5, 6, 7, 8), R]] // error
64+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9), R]] // error
65+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), R]] // error
66+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), R]] // error
67+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), R]] // error
68+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), R]] // error
69+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), R]] // error
70+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), R]] // error
71+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), R]] // error
72+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), R]] // error
73+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), R]] // error
74+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19), R]] // error
75+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), R]] // error
76+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), R]] // error
77+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), R]] // error
78+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23), R]] // error
79+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24), R]] // error
80+
the[TupledFunction[given erased (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) => R, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25), R]] // error
2981
}
3082
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
()
2+
(1)
3+
(1,3)
4+
(1,3,6)
5+
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
4+
val f0 = new Expr(() => ())
5+
val f1 = new Expr((i: Int) => Tuple1(i))
6+
val f2 = new Expr((i: Int, j: Int) => (i, i + j))
7+
val f3 = new Expr((i: Int, j: Int, k: Int) => (i, i + j, i + j + k))
8+
val f25 = new Expr(
9+
(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int, x24: Int, x25: Int) =>
10+
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25)
11+
)
12+
13+
println(f0())
14+
println(f1(1))
15+
println(f2(1, 2))
16+
println(f3(1, 2, 3))
17+
println(f25(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25))
18+
19+
}
20+
21+
class Expr[T](val x: T)
22+
23+
// Specialized only for arity 0 and one as auto tupling will not provide the disired effect
24+
def (e: Expr[() => R]) apply[R](): R = e.x()
25+
def (e: Expr[Arg => R]) apply[Arg, R](arg: Arg): R = e.x(arg)
26+
27+
// Applied to all funtions of arity 2 or more (including more than 22 parameters)
28+
def (e: Expr[F]) apply[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, Args, R]): R = {
29+
tf.applyFunctionTo(e.x, args)
30+
}
31+
32+
}

0 commit comments

Comments
 (0)