Skip to content

Misleading error message when matching on quotes #6991

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

minimized code

Macro file:

package playground

import scala.quoted._
import scala.quoted.matching._

object macros {
  inline def mcr(x: => Any): Any = ${mcrImpl('x)}

  class Foo // { def apply(str: String) = "100" }

  def mcrImpl(body: Expr[Any])(using ctx: QuoteContext): Expr[Any] = {
    import ctx.tasty._
    body match {
      case '{($x: Foo)($bar: String)} => '{"Hello World"}
    }
  }
}

Main file:

package playground

import playground.macros._


val foo = new Foo
@main def main = println(mcr(foo("100")))

Error:

[error] -- [E050] Reference Error: /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala:15:14
[error] 15 |      case '{($x: Foo)($bar: String)} => '{"Hello World"}
[error]    |              ^^^^^^^
[error]    |             method exprSplice in object Quoted does not take parameters
[error] one error found

If you uncomment the body of the Foo class, everything works as expected and "Hello World" is printed out.

If you replace the case clause with:

case '{($x: Foo).apply($bar: String)} => '{"Hello World"}

The error changes:

[error] -- [E008] Member Not Found Error: /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala:15:23
[error] 15 |      case '{($x: Foo).apply($bar: String)} => '{"Hello World"}
[error]    |             ^^^^^^^^^^^^^^^
[error]    |             value apply is not a member of playground.macros.Foo
[error] one error found

expectation

I would expect the latter error to be displayed also in the former case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions