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

applyDynamic macro fails for nested application #7777

Closed
scabug opened this issue Aug 22, 2013 · 5 comments
Closed

applyDynamic macro fails for nested application #7777

scabug opened this issue Aug 22, 2013 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Aug 22, 2013

Consider this implementation of applyDynamic:

object Dyn extends Dynamic {
  def applyDynamic(s: String)(xs: Any*): Dyn.type = {
    println(s + xs.map(_.toString).mkString("(", ", ", ")"))
    Dyn
  }
}

This works as expected:

  Dyn.foo(1, 2)              // prints "foo(1, 2)"
  Dyn.foo(3).bar(4, 5)       // prints "foo(3)", then "bar(4, 5)"
  Dyn(6).bar(7)              // prints "apply(6)", then "bar(7)"
  Dyn.foo(8)(9)              // prints "foo(8)", then "apply(9)"

This somewhat analogous macro implementation works in all but the last case:

class DynMacro extends Dynamic {
  def applyDynamic(s: String)(xs: Any*): DynMacro =
    macro DynMacro.applyDynamicMacro
}

object DynMacro extends DynMacro {
  def applyDynamicMacro(c: Context)(s: c.Expr[String])(xs: c.Expr[Any]*): c.Expr[DynMacro] = {
    import c.universe._
    val Literal(Constant(n: String)) = s.tree
    val args = xs.map(_.tree.toString).mkString("(", ", ", ")")
    c.Expr(q"println(${ n + args }); ${c.prefix.tree}")
  }
}
  DynMacro.foo(1, 2)         // prints "foo(1, 2)"
  DynMacro.foo(3).bar(4, 5)  // prints "bar(4, 5)", then "foo(3)"
  DynMacro(6).bar(7)         // prints "bar(7)", then "apply(6)"
  DynMacro.foo(8)(9)         // Fails!

The last case results in an unhandled AssertionError "assertion failed: DynMacro.foo(8)(9)" somewhere in SuperAccessors, but the actual error probably happens much earlier.

This may or may not be related to #7059.

@scabug
Copy link
Author

@scabug scabug commented Aug 22, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7777?orig=1
Reporter: @sstucki
Affected Versions: 2.10.3-RC1, 2.11.0-M4
See #7914

@scabug
Copy link
Author

@scabug scabug commented Aug 22, 2013

@xeno-by said:
Looks like an unfortunate mismatch of points in time when macros and dynamics are handled. How urgent is this bug for you to fix?

@scabug
Copy link
Author

@scabug scabug commented Aug 22, 2013

@sstucki said:
Experimenting with dynamic macros. Not a blocker for now.

@scabug
Copy link
Author

@scabug scabug commented Dec 26, 2013

@xeno-by said (edited on Dec 26, 2013 7:00:04 PM UTC):
Seems related to #7914, because changing DynMacro.foo(8)(9) to DynMacro.foo(8).apply(9) works.

@scabug
Copy link
Author

@scabug scabug commented Dec 27, 2013

@xeno-by said:
Pull request: scala/scala#3309. Thanks for the detailed report!

@scabug scabug closed this Dec 30, 2013
@scabug scabug added this to the 2.11.0-M8 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants