fix: Skip pattern analysis on type mismatches

This commit is contained in:
Shoyu Vanilla 2025-05-28 08:11:14 +09:00
parent 7230ded9c7
commit 8682c1b9b4
2 changed files with 17 additions and 0 deletions

View File

@ -324,6 +324,9 @@ impl ExprValidator {
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
continue;
};
if self.infer.type_mismatch_for_pat(pat).is_some() {
continue;
}
let Some(initializer) = initializer else { continue };
let ty = &self.infer[initializer];
if ty.contains_unknown() {

View File

@ -1243,4 +1243,18 @@ fn foo(v: &Enum) {
"#,
);
}
#[test]
fn regression_19844() {
check_diagnostics(
r#"
fn main() {
struct S {}
enum E { V() }
let E::V() = &S {};
// ^^^^^^ error: expected S, found E
}
"#,
);
}
}