jakt icon indicating copy to clipboard operation
jakt copied to clipboard

Typechecker: Matchings that yield optionals cannot infer the type of `None`

Open greytdepression opened this issue 2 years ago • 1 comments

The following code fails to compile, because the typechecker does not know how to handle None here.

function foo() -> bool? => match 0 {
    1 => false
    else => None
}

function main() {
    let a = foo()
}

The error (in which the types are flipped, but that's for another issue :^) ) is

Error: Type mismatch: expected ‘unknown’, but got ‘bool’
 10 |     false => false 
 11 |     else => None 
                  ^- Type mismatch: expected ‘unknown’, but got ‘bool’
 12 | } 
-----

greytdepression avatar Jun 16 '22 20:06 greytdepression

Hey there! I'd like to take a look into this. I'll reach out on discord with any questions I have.

steven-mathew avatar Jun 16 '22 20:06 steven-mathew

fixed as of 1ea81c6. filed #1139 as a follow up for type inference.

lanmonster avatar Sep 01 '22 16:09 lanmonster