effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

Misleading error message when mutable variable shadows outer function #641

Open jiribenes opened 1 month ago

jiribenes commented 1 month ago

The following code has a somewhat misleading error message: there is a sum which is mutable, it's just not something we can reach:

Screenshot 2024-10-14 at 15 01 15
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.

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