Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-RC1, Scala 2.11.0-M1
    • Fix Version/s: Scala 2.10.1
    • Component/s: Macros
    • Environment:

      Scala compiler version 2.11.0-20121023-093421-b480d99107
      (master)

      Description

      Given these data types:

      trait Outer {
        trait Inner[T]
        def make[T](t: T): Inner[T] = ???
      }
      object Def extends Outer
      

      the following shows that inside `reify`, `Def.Inner` is treated as `Outer.this.Inner`, causing a type mismatch.

      Macro implementation:

      import language.experimental.macros
      import scala.reflect.macros._
      
      import Def.Inner
      object Test {
        def id[T](t: Inner[T]): Inner[T] = macro idImpl[T]
      
        def idImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[Inner[T]]): c.Expr[Inner[T]] =
          c.universe.reify {
            val v: Def.Inner[T] = t.splice
            v
          }
      }
      

      Macro usage:

      object Use {
        val y = Test.id(Def.make(3))
      }
      

      The type mismatch error generated when compiling Use is below. The mismatch is from the first line of the reify block.

      Use.scala:2: error: type mismatch;
       found   : Def.Inner[Int]
       required: Outer.this.Inner[Int]
      
              val y = Test.id(Def.make(3))
                                      ^
      Use.scala:2: error: type mismatch;
       found   : Outer.this.Inner[Int]
       required: Def.Inner[Int]
      
              val y = Test.id(Def.make(3))
                             ^
      two errors found
      

        Activity

        Hide
        Eugene Burmako added a comment -

        Luckily, this isn't a fundamental problem as I feared. It's just an oversight in the reifier.

        The problem is that when `reifyBoundType` in GenTrees.scala sees a Select(_, _), it happily assumes that it's enough to just reify the underlying symbol and wrap it in a Ident.

        Show
        Eugene Burmako added a comment - Luckily, this isn't a fundamental problem as I feared. It's just an oversight in the reifier. The problem is that when `reifyBoundType` in GenTrees.scala sees a Select(_, _), it happily assumes that it's enough to just reify the underlying symbol and wrap it in a Ident.
        Hide
        Josh Suereth added a comment -

        Eugene - Do you think we can get a fix for this by 2.10.1?

        Show
        Josh Suereth added a comment - Eugene - Do you think we can get a fix for this by 2.10.1?
        Hide
        Eugene Burmako added a comment -

        Sorry Josh, missed this comment. Yes we definitely can.

        Show
        Eugene Burmako added a comment - Sorry Josh, missed this comment. Yes we definitely can.
        Hide
        Eugene Burmako added a comment -

        This bug is being fixed

        Show
        Eugene Burmako added a comment - This bug is being fixed
        Hide
        Eugene Burmako added a comment -

        The patch will arrive this Wednesday

        Show
        Eugene Burmako added a comment - The patch will arrive this Wednesday
        Show
        James Iry added a comment - https://github.com/scala/scala/pull/2072
        Hide
        James Iry added a comment -
        Show
        James Iry added a comment - superseded by https://github.com/scala/scala/pull/2094

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Mark Harrah
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development