summaryrefslogtreecommitdiff
path: root/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala
blob: 3d350a50fa9c80f1f07c5ea44ee4a15d47e9c124 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import scala.reflect.runtime.universe._
import scala.reflect.macros.Context

object Macros {
  def cons_impl[A: c.AbsTypeTag](c: Context)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = c.universe.reify {
    println("A = " + c.literal(implicitly[c.AbsTypeTag[A]].toString).splice)
    x.splice :: xs.splice
  }

  def nil_impl[B: c.AbsTypeTag](c: Context): c.Expr[List[B]] = c.universe.reify {
    println("B = " + c.literal(implicitly[c.AbsTypeTag[B]].toString).splice)
    Nil
  }

  def cons[A](x: A, xs: List[A]): List[A] = macro cons_impl[A]

  def nil[B]: List[B] = macro nil_impl[B]
}