docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

Scala 3 Metaprogramming Reference has some invalid example code

Open coreywoodfield opened this issue 3 years ago • 0 comments

The example here is as follows:

def collectPatternVariables(tree: Tree)(using ctx: Context): List[Symbol] =
  val acc = new TreeAccumulator[List[Symbol]]:
    def foldTree(syms: List[Symbol], tree: Tree)(owner: Symbol): List[Symbol] = tree match
      case ValDef(_, _, rhs) =>
        val newSyms = tree.symbol :: syms
        foldTree(newSyms, body)(tree.symbol)
      case _ =>
        foldOverTree(syms, tree)(owner)
  acc(Nil, tree)

Where does body come from? I'm guessing the pattern should maybe be ValDef(_, body, rhs) but I'm not 100% sure

coreywoodfield avatar Jan 07 '22 20:01 coreywoodfield