Scala Programming Language
  1. Scala Programming Language
  2. SI-6662

Compile error when passing unit to infix macro

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-M2
    • Fix Version/s: Scala 2.10.0
    • Component/s: Macros
    • Labels:
      None

      Description

      Macro definition:

      import language.experimental.macros
      import scala.reflect.macros.Context
      
      object Demo {
        def id[T](a: T): T = macro idImpl[T]
      
        def idImpl[T: c.WeakTypeTag](c: Context)(a: c.Expr[T]): c.Expr[T] = a
      }
      

      Macro usage:

      object Usage {
         def main(args: Array[String]) {
            val s = Demo id ()
            println(s)
         }
      }
      

      This fails to compile with the error:

      Use.scala:3: macros application do not support named and/or default arguments
            val s = Demo id ()
                         ^
      

      If id is not a macro, this compiles and prints () as expected. Workarounds include not using infix or a right hand side of (()) or {}.

        Activity

        Show
        Paul Phillips added a comment - https://github.com/scala/scala/pull/1617
        Hide
        Mark Harrah added a comment -

        "Who knows what someone might be doing with a Unit." is a reasonable comment, so here's the justification...

        1. As much as possible, I should be able to replace a normal method with a macro without affecting clients of that method.
        2. The specific situation where this might come up is when a user redefines a previously side-effecting task to do nothing, such as publish := () to disable publishing. Examples usually use {}, but because () is allowed for normal methods, we're back to number 1.

        Show
        Mark Harrah added a comment - "Who knows what someone might be doing with a Unit." is a reasonable comment, so here's the justification... 1. As much as possible, I should be able to replace a normal method with a macro without affecting clients of that method. 2. The specific situation where this might come up is when a user redefines a previously side-effecting task to do nothing, such as publish := () to disable publishing. Examples usually use {}, but because () is allowed for normal methods, we're back to number 1.
        Hide
        Paul Phillips added a comment -

        I realize it's hard to tell when I'm kidding, but I would never suggest a bug like this doesn't merit fixing.

        Show
        Paul Phillips added a comment - I realize it's hard to tell when I'm kidding, but I would never suggest a bug like this doesn't merit fixing.
        Show
        Eugene Burmako added a comment - Fixed in https://github.com/scala/scala/commit/b9225732889448378ccb880faa6d8421cf40e02c

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Mark Harrah
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development