-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Macro does not always elide its receiver #5110
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
Comments
The receiver is not by-name, so it cannot be elided. |
In general we must not elide the receiver or else we would change the semantics function application. |
Even if it is by-name, is it not elided: class Test {
def test(): String = {
val $1$: Macro.Macro$StringContextOps =
new Macro.Macro$StringContextOps(
{
closure(<empty>.this.$anonfun$1:Function0)
}
)
""
}
private final <static> def $anonfun$1(): StringContext =
root_.scala.StringContext.apply(
Predef.wrapRefArray(["Hello World" : String])
)
} But when I write: class Foo {
rewrite def foo: String = ~Macro.impl
}
object Macro {
def impl: Expr[String] = '("")
} class Test {
def test = (new Foo).foo
} The full call to the macro |
Previously we did rely on the optimizer to remove the remaining unused |
With the new syntax for extension method we can create a by name prefix which is elided if not used.
Let's consider the following macro based string interpolator
And the following use case:
which expands to:
My expectation (and how it works in Scala 2) is that the receiver of the macro gets elided
The text was updated successfully, but these errors were encountered: