Skip to content

Missing macros to get Expr and raw source code of method arguments #5782

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

Closed
alexarchambault opened this issue Jan 23, 2019 · 7 comments
Closed

Comments

@alexarchambault
Copy link
Contributor

It's the main issue I ran into when porting sourcecode to dotty. It needs macros to

  • get the arguments of ~the root context (like in def foo(a: Int, b: String)(implicit foo: Foo) with the implicit materialization of Foo backed by a macro - how can the macro get Exprs for 2 and "a" in f(2, "a")?). Prevents to have sourcecode.Args work fine.
  • get the ~raw code of arguments of the root context (in def foo(s: Seq[Int])(implicit foo: Foo), with the implicit materialization of Foo backed by a macro - how can the macro get a String "(1 to 10).sum" in f((1 to 10).sum)?). Prevents to have sourcecode.Text work fine.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 7, 2019
Partial fix for scala#5782:
* get the ~raw code of arguments of the root context (in `def foo(s: Seq[Int])(implicit foo: Foo)`, with the implicit materialization of `Foo` backed by a macro - how can the macro get a String `"(1 to 10).sum"` in `f((1 to 10).sum)`?). Prevents to have `sourcecode.Text` work fine.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 12, 2019
Partial fix for scala#5782:
* get the ~raw code of arguments of the root context (in `def foo(s: Seq[Int])(implicit foo: Foo)`, with the implicit materialization of `Foo` backed by a macro - how can the macro get a String `"(1 to 10).sum"` in `f((1 to 10).sum)`?). Prevents to have `sourcecode.Text` work fine.
@nicolasstucki
Copy link
Contributor

@alexarchambault is the addition in #5870 enough to implement this macro?

@alexarchambault
Copy link
Contributor Author

@nicolasstucki I guess it is for the second point. Don't know about the first.

@alexarchambault
Copy link
Contributor Author

Checking right now for the second point.

@nicolasstucki
Copy link
Contributor

For the first one you should try with (args: Expr[T]).unseal.underlyingArgument

@alexarchambault
Copy link
Contributor Author

So using sourceCode fails like this (PR).

About Args, I'm not sure how I'm supposed to recover the Expr[_] of the arguments from the root context.

@nicolasstucki
Copy link
Contributor

@alexarchambault could you create a self contained example that shows the desired result?

@nicolasstucki
Copy link
Contributor

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

3 participants