Skip to content

Misleading error message when matching on quotes #6991

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
anatoliykmetyuk opened this issue Aug 5, 2019 · 0 comments · Fixed by #17342
Closed

Misleading error message when matching on quotes #6991

anatoliykmetyuk opened this issue Aug 5, 2019 · 0 comments · Fixed by #17342
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@anatoliykmetyuk
Copy link
Contributor

anatoliykmetyuk commented Aug 5, 2019

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.

@nicolasstucki nicolasstucki removed their assignment Jan 29, 2020
@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed area:metaprogramming labels Feb 7, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 25, 2023
@nicolasstucki nicolasstucki linked a pull request May 2, 2023 that will close this issue
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants