It looks to me like we aren't checking generic functions "on their own". Instead, we only check them with type variables filled in at their call sites. This leads to quite strange error reporting and in some cases even C++ that doesn't compile.
Currently, writing this is not an error:
fn to_minus_42<T>(anon a: T) -> T {
return -42
}
fn main() {
to_minus_42(-12)
}
However, this is:
fn to_minus_42<T>(anon a: T) -> T {
return -42
}
fn main() {
to_minus_42(12 as! u32)
}
Also notice where it is reported:
Error: Type mismatch: expected βu32β, but got βi64β
ββββ¬β src/main.jakt:2:5
1 β fn to_minus_42<T>(anon a: T) -> T {
2 β return -42
β ββββββββββ¬
β β°β Type mismatch: expected βu32β, but got βi64β
3 β }
ββββ΄β
Lastly, consider this case, which will type check but doesn't compile:
fn unwrap<T>(anon a: Optional<T>) -> T {
return None
}
fn main() {
unwrap(Some(42))
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too