The following code has a somewhat misleading error message: there is a sum which is mutable, it's just not something we can reach:
The code in question
```scala
def sum(xs: List[Int]): Int = {
var sum = xs.foreach { x =>
sum = sum + x
// ^ ~~~
}
sum
}
```
Of course when you use res for the mutable variable and keep sum for the function, you get Could not resolve term res, which is probably a better message in this case.
The following code has a somewhat misleading error message: there is a
sum
which is mutable, it's just not something we can reach:The code in question
```scala def sum(xs: List[Int]): Int = { var sum = xs.foreach { x => sum = sum + x // ^ ~~~ } sum } ```Of course when you use
res
for the mutable variable and keepsum
for the function, you getCould not resolve term res
, which is probably a better message in this case.I have no real use case for this, I just introduced a typo by accident in https://effekt-lang.org/tour/variables and then wondered for a brief moment.
Here's the relevant compiler code: https://github.com/effekt-lang/effekt/blob/afb9ef015b2f18e56958f43235c711f05612dc9e/effekt/shared/src/main/scala/effekt/Namer.scala#L516-L521