effekt-lang / effekt-lang/effekt

Misleading error message when mutable variable shadows outer function

Open
#641 0 comments 0 reactions 0 assignees View on GitHub
errormessage
Dominant language
Scala
Stars
469
Forks
41
Avg merge
1d 16h
Merged PRs (30d)
23

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.