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:
parent
c1c2cd97b7
commit
4ca73c4cdf
|
@ -323,6 +323,29 @@ fn mark_constructors_as_used_via_field_access() {
|
||||||
assert_eq!(warnings.len(), 1)
|
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]
|
#[test]
|
||||||
fn validator_correct_form() {
|
fn validator_correct_form() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
|
|
|
@ -1992,6 +1992,8 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
is_validator_param: false,
|
is_validator_param: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pattern_is_var = pattern.is_var();
|
||||||
|
|
||||||
continuation.insert(
|
continuation.insert(
|
||||||
0,
|
0,
|
||||||
UntypedExpr::Assignment {
|
UntypedExpr::Assignment {
|
||||||
|
@ -2010,6 +2012,11 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
// erase backpassing while preserving assignment kind.
|
// erase backpassing while preserving assignment kind.
|
||||||
kind: match kind {
|
kind: match kind {
|
||||||
AssignmentKind::Let { .. } => AssignmentKind::let_(),
|
AssignmentKind::Let { .. } => AssignmentKind::let_(),
|
||||||
|
AssignmentKind::Expect { .. }
|
||||||
|
if pattern_is_var && annotation.is_none() =>
|
||||||
|
{
|
||||||
|
AssignmentKind::let_()
|
||||||
|
}
|
||||||
AssignmentKind::Expect { .. } => AssignmentKind::expect(),
|
AssignmentKind::Expect { .. } => AssignmentKind::expect(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue