File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ 3
2
+ 3
Original file line number Diff line number Diff line change
1
+ // https://github.com/lampepfl/dotty/issues/11706
2
+ import scala .compiletime .erasedValue
3
+
4
+ object Obj :
5
+
6
+ inline def length [Tuple ]: Int = loop[Tuple ]
7
+
8
+ private inline def loop [Tuple ]: Int =
9
+ inline erasedValue[Tuple ] match
10
+ case _ : EmptyTuple => 0
11
+ case _ : (head *: tail) => 1 + loop[tail]
12
+
13
+ end Obj
14
+
15
+ // Same code, but in a trait instead of an object
16
+ trait Trait :
17
+
18
+ inline def length [Tuple ]: Int = loop[Tuple ]
19
+
20
+ private inline final def loop [Tuple ]: Int =
21
+ inline erasedValue[Tuple ] match
22
+ case _ : EmptyTuple => 0
23
+ case _ : (head *: tail) => 1 + loop[tail]
24
+
25
+ end Trait
26
+
27
+ @ main def Test () =
28
+ println(Obj .length[(Int , Int , String )]) // OK
29
+ new Trait :
30
+ println(length[(Int , Int , String )])
You can’t perform that action at this time.
0 commit comments