Open bhansconnect opened 1 year ago
Having worked a bit on the issue, I am logging here my progress. I came up with a simpler repro that can be added to
crates/compiler/solve/tests/solve_expr.rs
#[test]
fn optional_field_bug() {
infer_eq_without_problem(
indoc!(
r#"
f : { val ? Bool } -> Bool
f = \{val ? Bool.false} -> val
g = f {val: Bool.true}
f
"#
),
"{ val ? Bool } -> Bool",
);
}
That test fails with:
---- solve_expr::optional_field_bug stdout ----
thread 'solve_expr::optional_field_bug' panicked at 'assertion failed: `(left == right)`
Diff < left / right > :
<{ val : Bool } -> Bool
>{ val ? Bool } -> Bool
Somehow it seems that type-checking the g
function changes the signature of f
. Other interesting observations are:
f
makes it work as expected. The inferred type of f
is rightly { val ? Bool }* -> Bool
in this case{ val ? Bool }* -> Bool
for f
also works as expected
Apparently using an optional record field as both optional and required can break type checking:
put this in repl or any file and roc check it:
will get: