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

Macros have same type after erasure #7776

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

Macros have same type after erasure #7776

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

Comments

@scabug
Copy link

scabug commented Aug 22, 2013

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?

@scabug
Copy link
Author

scabug commented Aug 22, 2013

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

@scabug
Copy link
Author

scabug commented Aug 22, 2013

@xeno-by said:
Yep, the failure is indeed spurious. How much of a blocker is this bug for you?

@scabug
Copy link
Author

scabug commented Aug 22, 2013

@sstucki said:
Using it for some experimental stuff. Not really a blocker for now.

@scabug
Copy link
Author

scabug commented Oct 18, 2013

@xeno-by said:
scala/scala#3054

@scabug
Copy link
Author

scabug commented Nov 5, 2013

@xeno-by said:
scala/scala#3101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants