tree-sitter-scala icon indicating copy to clipboard operation
tree-sitter-scala copied to clipboard

Folding for nested `def`s (or something) in Scala 3

Open simlei opened this issue 2 years ago • 0 comments

Folding does not quite work on nested def I encountered; Forgive the code not compiling — I tried to minimize it aggressively and quickly, rather than make it compile. The fold that is supposed to be around def of(base: BaseT) terminates only after it encounters the case class. Screenshot:

image

Code:

package bla

object DevRun:
  trait TreeishSuper:
      def of(base: BaseT): T =
        def getterIfNotPresent =
          NodeTreeish.childrenOf(base) match
            case Vector() => construct(base, Vector())
            case children @ _ => construct(base, children.toVector.map{of(_)})
        cache.getOrElseUpdate(base, getterIfNotPresent)

  case class Plan(val instructions: Vector[PlanInstruction], val targetNodes: Vector[NT]):
    val inputs_targets = for { t <- targetNodes; i <- pushingNodes } yield (i,t)
    val pushingToOutputs = for { t <- graph.outputNodes; i <- pushingNodes } yield (i,t)
    val allWalksWithActives = shape.graph.dag.linearWalksAtoB.filter{ w => w.toList.exists{targetNodes.contains(_) && pushingNodes.contains(w.origin) }}
end DevRun

Note that this happens even if the whole file compiles.

simlei avatar Jun 07 '22 13:06 simlei