enlightware / enlightware/ferlium

Improve error message where defaulting fails in expression

Open
#62 0 comments 0 reactions 0 assignees View on GitHub
error messages trait type
Dominant language
Rust
Stars
14
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Given this code:
```
fn nop(a: &? [_], f) {
f(a)
}

let mut a = [5, 4, 11, 3, 2, 1, 0, 7];
nop(a[0], |x| x)
```

Compilation fails because the call to `nop(a[0], |x| x)` requires `a[0]` to be a `Num`, but the signature of `nop` requires a[0] to be an array. This leads to this constraint: `[A]: Num`, which cannot be satisfied. So this should be the error.

However, no error is emitted at that point and constraint solving is deferred, leading to the following error at the end: `Unbound type variable A in type [A]`.

If used in a function:
```
fn f() {
let mut a = [5, 4, 11, 3, 2, 1, 0, 7];
nop(a[0], |x| x)
}
```

No issue arises because then `f` simply has the signature: `f() -> [A] where [A]: Num`, which is a fine signature.

Ideally, we could add some smarter error messages when type defaulting fails in expressions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.