Skip to content

inline val/defs can't be used when calling a quotes fn #12196

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
japgolly opened this issue Apr 22, 2021 · 3 comments · Fixed by #12235
Closed

inline val/defs can't be used when calling a quotes fn #12196

japgolly opened this issue Apr 22, 2021 · 3 comments · Fixed by #12235
Assignees
Milestone

Comments

@japgolly
Copy link
Contributor

japgolly commented Apr 22, 2021

Compiler version

This used to work in RC1. It fails in RC2 and RC3.

Minimized code

import scala.quoted.*

def qqq(s: String)(using Quotes): Expr[Unit] = '{()}

inline val InlineVal = "i"
inline def InlineDef = "i"

inline def withInlineVal = ${ qqq(InlineVal) }
inline def withInlineDef = ${ qqq(InlineDef) }
inline def withString    = ${ qqq("i") }

Output

[error] -- Error: x.scala:8:34 --------------
[error] 8 |inline def withInlineVal = ${ qqq(InlineVal) }
[error]   |                                  ^^^^^^^^^
[error]   |                                  Malformed macro parameter
[error]   |
[error]   |                                  Parameters may only be:
[error]   |                                   * Quoted parameters or fields
[error]   |                                   * Literal values of primitive types
[error] -- Error: x.scala:9:34 --------------
[error] 9 |inline def withInlineDef = ${ qqq(InlineDef) }
[error]   |                                  ^^^^^^^^^
[error]   |                                  Malformed macro parameter
[error]   |
[error]   |                                  Parameters may only be:
[error]   |                                   * Quoted parameters or fields
[error]   |                                   * Literal values of primitive types
[error] two errors found

Expectation

Compilation.

@nicolasstucki
Copy link
Contributor

This was restricted on purpose. We want to avoid inlining arbitrary code within the splice. All that code must be interpreted by a simple AST interpreter which is not fast compared with macro implementation that gets called. It is also impossible to impossible to implement an interpreter on the JVM that supports the full language.

It might be possible to support inline val only.

@smarter smarter changed the title Regression in RC2 & RC3: inline val/defs can't be used when calling a quotes fn inline val/defs can't be used when calling a quotes fn Apr 23, 2021
@odersky
Copy link
Contributor

odersky commented Apr 23, 2021

I think inline val should be supported. That seems counter-intuitive that we cannot abstract a constant.

@odersky
Copy link
Contributor

odersky commented Apr 23, 2021

Also, since it is a regression, we should classify it as a bug.

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

Successfully merging a pull request may close this issue.

4 participants