effekt-lang / effekt-lang/effekt

Type mismatch error gets reported as an overload error

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

Description

The following Effekt program:
```scala
def run(n: Int) { action: => Unit }: Unit = action()
def run(s: String) { action: => Unit }: Unit = action()
def add(a: Int, b: Int): Int = a + b

def main() = {
run(42) {
val s: Int = add(1, "Hello world!");
()
}
}
```
reports a type error in _overloading_ of `run`:
```
Cannot typecheck call.
There are multiple overloads, which all fail to check:

Possible overload: module0::run of type (Int){() => Unit} => Unit
Expected Int but got String. // <- the correct error

Possible overload: module0::run of type (String){() => Unit} => Unit
Expected String but got Int.
Expected Int but got String. // <- the correct error
```

However, the actual reported error should be that the second argument is of type `String`, whereas the expected type of the second parameter is `Int`.
Fortunately, this error still gets reported at the site of the `add` call so the user can still technically figure this out.

---

If we combine multiple weird overloads:
```scala
def run(n: Int) { action: => Unit }: Unit = action()
def run(s: String) { action: => Unit }: Unit = action()

def main() = {
run(42) {
"type error" ++ 42
}
}
```
we get a way more confusing message, telling the user that the overload of `run` failed, but the problem is that the overload of `++` failed:
```
Cannot typecheck call.
There are multiple overloads, which all fail to check:

Possible overload: module0::run of type (Int){() => Unit} => Unit
Expected String but got Int. // <- the correct error
Expected Unit but got String.

Possible overload: module0::run of type (String){() => Unit} => Unit
Expected String but got Int. // <- a new error? (from the `++` operator)
Expected String but got Int. // <- the correct error
Expected Unit but got String.
```

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.