Skip to content

Quotes pattern matching on object's member #14536

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
prolativ opened this issue Feb 22, 2022 · 0 comments · Fixed by #14732
Closed

Quotes pattern matching on object's member #14536

prolativ opened this issue Feb 22, 2022 · 0 comments · Fixed by #14732
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@prolativ
Copy link
Contributor

prolativ commented Feb 22, 2022

Compiler version

3.0.0 ... 3.1.3-RC1-bin-20220221-3ca087c-NIGHTLY

Minimized code

// Macro.scala

import quoted.*

inline def isFoo(inline x: Any): Boolean = ${ isFooImpl('x) }

def isFooImpl(x: Expr[Any])(using Quotes): Expr[Boolean] =
  x match
    case '{ ($p: Parent).foo } => '{ true }
    case _ => '{ false }
// Test.scala

trait Parent:
  def foo = 0

object Child extends Parent:
  def bar = isFoo(foo)

Output

[error] Test.scala:6:13: Exception occurred while executing macro expansion.
[error] java.lang.ClassCastException: class scala.Tuple$package$EmptyTuple$ cannot be cast to class scala.Tuple1 (scala.Tuple$package$EmptyTuple$ is in unnamed module of loader java.net.URLClassLoader @7291d7ca; scala.Tuple1 is in unnamed module of loader java.net.URLClassLoader @72b7b5a6)
[error]         at Macro$package$.isFooImpl(Macro.scala:7)
[error] 
[error]   def bar = isFoo(foo)
[error]             ^^^^^^^^^^

Expectation

The code should compile, matching the first case clause in isFooImpl. The example works correctly if Child is defined as a class rather than an object or foo is prefixed with this in the macro call like def bar = isFoo(this.foo)

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.

2 participants