Skip to content

Quotes pattern matching on object's member #14536

Closed
@prolativ

Description

@prolativ

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions