Skip to content

Macro implementation in REPL cannot be non-toplevel #15104

Closed
@prolativ

Description

@prolativ

Compiler version

3.2.0-RC1-bin-20220503-aff1e11-NIGHTLY

Minimized code

In REPL paste the two snippets below one after another

import scala.quoted.*

object Foo:
  def macroImpl(using Quotes) = Expr(1)

inline def foo = ${ Foo.macroImpl }
def x = foo

Output

-- Error: ----------------------------------------------------------------------
1 |def x = foo
  |        ^^^
  |        Could not find class rs$line$1$Foo$ in classpath
  |-----------------------------------------------------------------------------
  |Inline stack trace
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |This location contains code that was inlined from rs$line$1:6
6 |inline def foo = ${ Foo.macroImpl }
  |                 ^^^^^^^^^^^^^^^^^^
   -----------------------------------------------------------------------------
1 error found

Expectation

There should be no error, just like when macroImpl is a toplevel definition, e.g.

import scala.quoted.*

def macroImpl(using Quotes) = Expr(1)

inline def foo = ${ macroImpl }
def x = foo

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions