effekt
effekt copied to clipboard
Type mismatch error gets reported as an overload error
The following Effekt program:
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:
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.