Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error when passing unit to infix macro #6662

Closed
scabug opened this issue Nov 13, 2012 · 5 comments
Closed

Compile error when passing unit to infix macro #6662

scabug opened this issue Nov 13, 2012 · 5 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Nov 13, 2012

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 {}.

@scabug
Copy link
Author

@scabug scabug commented Nov 13, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6662?orig=1
Reporter: @harrah
Affected Versions: 2.10.0-M2

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 13, 2012

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 13, 2012

@harrah said:
"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.

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 13, 2012

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

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 14, 2012

@xeno-by said:
Fixed in scala/scala@b922573

Loading

@scabug scabug closed this Nov 14, 2012
@scabug scabug added the macros label Apr 7, 2017
@scabug scabug added this to the 2.10.0 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants