Skip to content

Commit e5fbe1c

Browse files
committed
Add indexed map test and couple of fixes
* Remove type vars from tasty types * Fix impure by name arguments to macros
1 parent f07bb38 commit e5fbe1c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tests/run/tasty-indexed-map/quoted_1.scala

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,32 @@ object MyMap {
1313
def create[Keys](implicit s: Size[Keys]): MyMap[Keys] = new MyMap[Keys](new Array[Int](s.size))
1414
}
1515

16-
trait Size[Keys] { def size: Int }
16+
class Size[HList](val size: Int) extends AnyVal
1717
object Size {
18-
def apply[Keys](v: Int): Size[Keys] = new Size { def size = v }
19-
implicit val unit: Size[Unit] = Size(0)
20-
implicit def cons[H, T](implicit s: Size[T]): Size[(H, T)] = Size(s.size + 1)
18+
type HList = Cons[_, _] | Unit
19+
type Cons[H, T <: HList] = (H, T)
20+
21+
implicit inline def getSize[HL <: HList]: Size[HL] = ~sizeImpl(Universe.compilationUniverse)('[HL])
22+
23+
def sizeImpl[HL <: HList](u: Universe)(implicit keys: Type[HL]): Expr[Size[HL]] = {
24+
import u._
25+
import u.tasty._
26+
27+
def sizeOf(tp: TypeOrBounds): Int = tp match {
28+
case Type.AppliedType(_, h :: t :: Nil) => 1 + sizeOf(t)
29+
case _ => 0
30+
}
31+
32+
val size = sizeOf(keys.toTasty.tpe)
33+
34+
'(new Size(~size.toExpr))
35+
}
2136
}
2237

2338
class Index[K, Keys](val index: Int) extends AnyVal
2439
object Index {
2540

26-
implicit def zero[K, T]: Index[K, (K, T)] = new Index(0)
41+
implicit inline def zero[K, T]: Index[K, (K, T)] = new Index(0)
2742

2843
implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ~succImpl(Universe.compilationUniverse)('[K], '[H], '[T])
2944

0 commit comments

Comments
 (0)