fix: closes #898
This is the best we can do for this without rearchitecting when we rewrite backpassing to plain ol' assignments. In this case, if we see a var and there is no annotation (thus probably not a cast), then it's safe to rewrite to a `let` instead of an `expect`. This way, we don't get a warning that is **unfixable**. We are not trying to solve every little warning edge case with this fix. We simply just can't allow there to be a warning that the user can't make go away through some means. All other edge cases like pattern matching on a single contructor type with expect warnings can be fixed via other means.
This commit is contained in:
@@ -323,6 +323,29 @@ fn mark_constructors_as_used_via_field_access() {
|
||||
assert_eq!(warnings.len(), 1)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_multi_patterns() {
|
||||
let source_code = r#"
|
||||
fn fold(list: List<a>, initial: b, apply: fn(a, b) -> b) {
|
||||
when list is {
|
||||
[] -> initial
|
||||
|
||||
[x, ..xs] -> fold(xs, apply(x, initial), apply)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn foo() {
|
||||
expect Some(x), acc <- fold([Some(1), None], 0)
|
||||
|
||||
x + acc
|
||||
}
|
||||
"#;
|
||||
|
||||
let (warnings, _) = check(parse(source_code)).unwrap();
|
||||
|
||||
assert_eq!(warnings.len(), 0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator_correct_form() {
|
||||
let source_code = r#"
|
||||
|
||||
Reference in New Issue
Block a user