Skip to content

Macro parameter inconsistencies #11688

Closed
@Jasper-M

Description

@Jasper-M

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions