Details

      Description

      Currently implicit defs, which are also macros, are expanded too early (typed1 in typedImplicit1), which means that they cannot be used to generate type tags.

      scala> def impl[T: c.WeakTypeTag](c: Context) = { println(c.weakTypeOf[T]); c.Expr[C[T]](c.universe.Literal(c.universe.Constant(null))) }
      impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[C[T]]
      
      scala> class C[T]defined class C
      
      scala> def impl[T: c.WeakTypeTag](c: Context) = { println(c.weakTypeOf[T]); c.Expr[C[T]](c.universe.Literal(c.universe.Constant(null))) }
      impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[C[T]]
      
      scala> implicit def foo[T]: C[T] = macro impl[T]
      foo: [T]=> C[T]
      
      scala> implicitly[C[Int]]
      <console>:30: foo is not a valid implicit value for C[Int] because:
      incompatible: C[T] does not match expected type C[Int]
                    implicitly[C[Int]]
                              ^
      <console>:30: error: could not find implicit value for parameter e: C[Int]
                    implicitly[C[Int]]
                              ^
      

        Activity

        Hide
        Leonard Schneider added a comment -

        Thanks Eugene. In the meantime I've found a dirty hack not to be completely blocked.

        Show
        Leonard Schneider added a comment - Thanks Eugene. In the meantime I've found a dirty hack not to be completely blocked.
        Hide
        Eugene Burmako added a comment -
        Show
        Eugene Burmako added a comment - Now the fix is for real: https://github.com/scala/scala/pull/2464
        Hide
        Eugene Burmako added a comment -
        Show
        Eugene Burmako added a comment - Updated PR: https://github.com/scala/scala/pull/2494
        Show
        Eugene Burmako added a comment - Fixed in https://github.com/scala/scala/commit/90ac5c4e1350493f6f47c674572c2dcb97b2b9eb
        Hide
        Eugene Burmako added a comment -
        Show
        Eugene Burmako added a comment - Also see https://issues.scala-lang.org/browse/SI-7470

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development