Skip to content

Can't use q"<foo></foo>" to match the passing tree #1

Description

@freewind

For the code:

Macros.manipulate(<foo></foo>)

If I define the manipulate as:

object Macros {
  def manipulate(elem: Elem): Elem = macro Bundle.impl
}

class Bundle(val c: Context) extends MacroLiftables {
  import c.universe._
  def impl(elem: Tree): Tree = {
    val q"<foo></foo>" = elem
    q"$result"
  }
}

It can never match:

[error] /Users/twer/workspace/xml-example/core/src/main/scala/Test.scala:17: exception during macro expansion:
[error] scala.MatchError: {
[error]   {
[error]     new scala.xml.Elem(null, "foo", scala.xml.Null, scala.this.xml.TopScope, false)
[error]   }
[error] } (of class scala.reflect.internal.Trees$Block)
[error]     at Bundle.impl(Macros.scala:17)
[error]   println(Macros.manipulate(<foo></foo>))
[error]                            ^
[error] one error found
[error] (core/compile:compile) Compilation failed
[error] Total time: 2 s, completed Mar 7, 2015 8:40:54 PM
>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions