Skip to content

Cannot call macro defined in the same source file error #12498

Closed
@mbore

Description

@mbore

Compiler version

3.0.1-RC1

Minimized code

MainMacro.scala

import scala.quoted.*

case class Wrapper[T](t: T) extends MainMacro[T]

trait MainMacro[U] { this: Wrapper[U] => 
  inline def showTypeRepr: String = ${ MainMacro.showTypeReprImpl[U]}
}

object MainMacro {
  def showTypeReprImpl[U: Type](using Quotes): Expr[String] = {
      import quotes.reflect.*
 
      val tpe = TypeRepr.of[U]

      Expr(tpe.toString)
  }
}

Test1.scala

object TestData {
  case class Person(name: String, age: Int)
}

class Test1 {

  import TestData.*

  // Notice that without inline does not work also
  inline def in(fun: => Any): Any = fun

  in {
    Wrapper(Person("a", 1)).showTypeRepr
  }
}

Output

$ mkdir classes
$ scalac -3.0.2-RC1 -d classes MainMacro.scala
$ scalac -3.0.2-RC1 -d classes -cp classes Test1.scala
-- Error: Test1.scala:13:28 ----------------------------------------------------
13 |    Wrapper(Person("a", 1)).showTypeRepr
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |    Cannot call macro class Person defined in the same source file
   | This location contains code that was inlined from Test1.scala:13
1 error found

Expectation

It should compile, I guess.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions