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 should be able to inject (implicit) definitions into their calling context #5774

Closed
scabug opened this issue May 8, 2012 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented May 8, 2012

It would be very useful if we could we write a macro,

def publish[T](t : T) = macro publishImpl(t)

def publishImpl[T](c : Context)(t : c.Expr[T]) = ...

such that when called,

publish("foo")

it expanded at the call site to,

implicit val <freshname> = "foo"

The following implementation suggested by Eugene,

import scala.reflect.makro.Context

object Macros {
   def publish = macro publishImpl

   def publishImpl(c : Context) = c.reify{implicit val foo: String = "foo"}
}

import Macros._

object Test extends App {
  publish;
  println(implicitly[String])
}

doesn't work "because (as far as I can guess by interpreting the error) macro expansion happens too late to be included in scope".

@scabug
Copy link
Author

scabug commented May 8, 2012

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

@scabug
Copy link
Author

scabug commented May 8, 2012

@scabug
Copy link
Author

scabug commented Dec 11, 2013

@xeno-by said:
Looks like now that we have working implicit macros, this is no longer necessary.

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