fix: Fix qual lookup

**Problem**
Nested macro that expands to map or mapN fails to
find the qual because the trees end up being different
between the record scan and actual replacement.

**Solution**
First try for equals normally, then compare the show strings.
This commit is contained in:
Eugene Yokota 2025-05-04 17:22:08 -04:00
parent 2ea0aac1bb
commit f3dd5dbd71
3 changed files with 21 additions and 1 deletions

View File

@ -266,7 +266,15 @@ trait Cont:
(name: String, tpe: Type[x], qual: Term, oldTree: Term) => (name: String, tpe: Type[x], qual: Term, oldTree: Term) =>
given Type[x] = tpe given Type[x] = tpe
convert[x](name, qual) transform { (replacement: Term) => convert[x](name, qual) transform { (replacement: Term) =>
val idx = inputs.indexWhere(input => input.qual == qual) val idxEq = inputs.indexWhere(input => input.qual == qual)
// use show to compare trees for Def.task comparison
val idx =
if idxEq < 0 then inputs.indexWhere(input => input.qual.show == qual.show)
else idxEq
if idx < 0 then
sys.error(
s"qual (${qual}) not found in ${inputs.map(_.qual)}"
)
applyTuple(p0, br.inputTupleTypeRepr, idx) applyTuple(p0, br.inputTupleTypeRepr, idx)
} }
val modifiedBody = val modifiedBody =

View File

@ -0,0 +1,11 @@
lazy val a1 = settingKey[Boolean]("")
scalaVersion := "3.6.4"
a1 := true
Compile / sourceGenerators += {
val _ = a1.value
Def.task {
Seq.empty[File]
}.taskValue
}

View File

@ -0,0 +1 @@
> compile