Skip to content

Macro parameter inconsistencies #11688

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
Jasper-M opened this issue Mar 10, 2021 · 1 comment · Fixed by #11746
Closed

Macro parameter inconsistencies #11688

Jasper-M opened this issue Mar 10, 2021 · 1 comment · Fixed by #11746
Milestone

Comments

@Jasper-M
Copy link
Contributor

Jasper-M commented Mar 10, 2021

Compiler version

3.0.0-RC1

Minimized code

Case 1

This compiles:

import scala.quoted._

def myMacro(a: Int)(using Quotes) = Expr(a)
def baz = 42
inline def bar = baz
inline def foo = ${myMacro(bar)}

Case 2

While this doesn't:

import scala.quoted._

def myMacro(a: Int)(using Quotes) = Expr(a)
def baz = 42
inline def foo = ${myMacro(baz)}
inline def foo = ${myMacro(baz)}
                           ^^^
                           Malformed macro parameter

                           Parameters may only be:
                            * Quoted parameters or fields
                            * Literal values of primitive types

Case 3

And this also doesn't compile:

import scala.quoted._

def myMacro(a: Int)(using Quotes) = Expr(a)
inline def foo(inline a: Int) = ${myMacro(a)}
inline def foo(inline a: Int) = ${myMacro(a)}
                                          ^
                           access to parameter a from wrong staging level:
                            - the definition is at level 0,
                            - but the access is at level -1.

Expectation

bar inlines to baz, so I would expect there to be no difference between calling bar or calling baz.
Both bar and a are inline so I would expect them to behave the same.

The answer here might seem to be that none of these 3 cases should compile. However the compiler itself told me that at least case 3 should also work:

      Malformed macro.

      Expected the splice ${...} to be at the top of the RHS:
        inline def foo(inline x: X, ..., y: Y): Int = ${impl(x, ... '{y}})

       * The contents of the splice must call a static method
       * All arguments must be quoted or inline
@nicolasstucki
Copy link
Contributor

Case 1 should have failed compilation.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 15, 2021
Also properly support canceled macro splices. These will warn the user and compile as if
they where a normal inline method.

Fixes scala#11688
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 22, 2021
Also properly support canceled macro splices. These will warn the user and compile as if
they where a normal inline method.

Fixes scala#11688
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

3 participants