Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.3-RC1, Scala 2.11.0-M4
    • Fix Version/s: Scala 2.11.0-M7
    • Component/s: Macros

      Description

      Compilation of the following fails:

      class MacroErasure {
        def app(f: Any => Any, x: Any): Any = macro MacroErasure.appMacro
        def app[A](f: A => Any, x: Any): Any = macro MacroErasure.appMacroA[A]
      }
      
      object MacroErasure {
        def appMacro(c: Context)(
          f: c.Expr[Any => Any], x: c.Expr[Any]): c.Expr[Any] = {
          import c.universe._
          c.Expr(q"$f($x)")
        }
        def appMacroA[A](c: Context)(f: c.Expr[A => Any], x: c.Expr[Any])(
          implicit tt: c.WeakTypeTag[A]): c.Expr[Any] = {
          import c.universe._
          c.Expr(q"$f[${tt.tpe}]($x)")
        }
      }
      

      The error message is:

      [error] /home/sast/projects/scala/scratch/src/main/scala/scratch/MacroErasure.scala:9: double definition:
      [error] macro method app:[A](f: A => Any, x: Any)Any and
      [error] macro method app:(f: Any => Any, x: Any)Any at line 8
      [error] have same type after erasure: (f: Function1, x: Object)Object
      [error]   def app[A](f: A => Any, x: Any): Any = macro MacroErasure.appMacroA[A]
      [error]       ^
      

      Can two macros really have the same type "after erasure"? Given that they are expanded at runtime, can this actually cause problems?

        Issue Links

          Activity

          Hide
          Eugene Burmako added a comment -

          Yep, the failure is indeed spurious. How much of a blocker is this bug for you?

          Show
          Eugene Burmako added a comment - Yep, the failure is indeed spurious. How much of a blocker is this bug for you?
          Hide
          Sandro Stucki added a comment -

          Using it for some experimental stuff. Not really a blocker for now.

          Show
          Sandro Stucki added a comment - Using it for some experimental stuff. Not really a blocker for now.
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/3054
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/3101

            People

            • Assignee:
              Eugene Burmako
              Reporter:
              Sandro Stucki
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development