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 cannot be loaded when inherited from a class or a trait #5753

Closed
scabug opened this issue May 3, 2012 · 5 comments
Closed

macros cannot be loaded when inherited from a class or a trait #5753

scabug opened this issue May 3, 2012 · 5 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 3, 2012

import scala.reflect.macros.Context
import language.experimental.macros

trait Impls {
  def impl(c: Context)(x: c.Expr[Any]) = x
}

object Macros extends Impls {
  def foo(x: Any) = macro impl
}
object Test extends App {
  import Macros._
  println(foo(42))
}
Macros_Test_2.scala:9: error: macro implementation not found: foo (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase
  println(foo(42))
             ^
one error found
@scabug
Copy link
Author

@scabug scabug commented May 3, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5753?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0-M3

Loading

@scabug
Copy link
Author

@scabug scabug commented May 3, 2012

@xeno-by said (edited on Nov 25, 2012 1:50:50 PM UTC):
Another manifestation:

import scala.reflect.macros.Context
import language.experimental.macros

trait ImplContainer {
  object Impls {
    def foo(c: Context)(x: c.Expr[Any]) = x
  }
}

object Macros extends ImplContainer {
  def foo(x: Any) = macro Impls.foo
}
object Test extends App {
  import Macros._
  println(foo(42))
}

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 23, 2012

@xeno-by said:
The issue is being fixed.

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 25, 2012

@xeno-by said (edited on Nov 25, 2012 1:51:21 PM UTC):
There's no way for the original example to compile:

import scala.reflect.makro.{Context => Ctx}

trait Impls {
  def impl(c: Ctx)(x: c.Expr[Any]) = x
}
import scala.reflect.makro.{Context => Ctx}

object Macros extends Impls {
  def foo(x: Any) = macro impl
}

object Test extends App {
  import Macros._
  println(foo(42))
}

Therefore I've updated the bug description with something legible. This one would make a nice test case, though.

Loading

@scabug
Copy link
Author

@scabug scabug commented Nov 29, 2012

@xeno-by said:
Fixed in scala/scala@597a949

Loading

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