Skip to content

Commit

Permalink
Remove unnecessary freshname and add describe transformation.
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-ali authored and Baccata committed Oct 9, 2024
1 parent a9bde78 commit 8aeb1bc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/core/shared/src/main/scala-2/weaver/ExpectMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,23 @@ private[weaver] object ExpectMacro {
value: c.Tree): c.Tree = {

import c.universe._

// This transformation outputs code that adds clues to a local
// clues collection `cluesName`. It recurses over the input code and replaces
// all calls of `ClueHelpers.clue` with `cluesName.addClue`.
object transformer extends Transformer {

override def transform(input: Tree): Tree = input match {
case c.universe.Apply(fun, List(clueValue))
if fun.symbol == clueMethodSymbol =>
// The input tree corresponds to `ClueHelpers.clue(clueValue)` .
// Transform it into `clueName.addClue(clueValue)`
// Apply the transformation recursively to `clueValue` to support nested clues.
val transformedClueValue = super.transform(clueValue)
val clueName = TermName(c.freshName("clue$"))
q"""{val $clueName = ${transformedClueValue}; ${cluesName}.addClue($clueName)}"""
case o => super.transform(o)
q"""${cluesName}.addClue($transformedClueValue)"""
case o =>
// Otherwise, recurse over the input.
super.transform(o)
}
}

Expand Down

0 comments on commit 8aeb1bc

Please sign in to comment.