Skip to content

Commit

Permalink
fix(hir): missing validators in test diagnostics (mun-lang#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann authored and Isabela Case committed Jun 11, 2023
1 parent 175a5d8 commit 6726db4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
16 changes: 8 additions & 8 deletions crates/mun_hir/src/expr/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn test_uninitialized_access() {
insta::assert_snapshot!(
diagnostics(r#"
fn foo() {
let a:int;
let a:i64;
let b = a + 3;
}
"#), @"38..39: use of possibly-uninitialized variable"
Expand All @@ -18,31 +18,31 @@ fn test_uninitialized_access_if() {
insta::assert_snapshot!(diagnostics(
r#"
fn foo() {
let a:int;
let a:i64;
if true { a = 3; } else { a = 4; }
let b = a + 4; // correct, `a` is initialized either way
}
fn bar() {
let a:int;
let a:i64;
if true { a = 3; }
let b = a + 4; // `a` is possibly-unitialized
}
fn baz() {
let a:int;
let a:i64;
if true { return } else { a = 4 };
let b = a + 4; // correct, `a` is initialized either way
}
fn foz() {
let a:int;
let a:i64;
if true { a = 4 } else { return };
let b = a + 4; // correct, `a` is initialized either way
}
fn boz() {
let a:int;
let a:i64;
return;
let b = a + 4; // `a` is not initialized but this is dead code anyway
}
Expand All @@ -54,8 +54,8 @@ fn test_uninitialized_access_if() {
fn test_uninitialized_access_while() {
insta::assert_snapshot!(diagnostics(
r#"
fn foo(b:int) {
let a:int;
fn foo(b:i64) {
let a:i64;
while b < 4 { b += 1; a = b; a += 1; }
let c = a + 4; // `a` is possibly-unitialized
}
Expand Down
27 changes: 3 additions & 24 deletions crates/mun_hir/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
#[cfg(test)]
pub mod tests {
use crate::{
code_model::r#struct::validator::StructValidator,
diagnostics::DiagnosticSink,
expr::validator::{ExprValidator, TypeAliasValidator},
mock::MockDatabase,
with_fixture::WithFixture,
FileId, ModuleDef, Package,
diagnostics::DiagnosticSink, mock::MockDatabase, with_fixture::WithFixture, Package,
};

pub fn diagnostics(content: &str) -> String {
Expand All @@ -29,24 +24,8 @@ pub mod tests {
diags.push(format!("{:?}: {}", diag.highlight_range(), diag.message()));
});

for item in Package::all(&db)
.iter()
.flat_map(|pkg| pkg.modules(&db))
.flat_map(|module| module.declarations(&db))
{
match item {
ModuleDef::Function(item) => {
ExprValidator::new(item, &db).validate_body(&mut diag_sink);
}
ModuleDef::TypeAlias(item) => {
TypeAliasValidator::new(item, &db)
.validate_target_type_existence(&mut diag_sink);
}
ModuleDef::Struct(item) => {
StructValidator::new(item, &db, FileId(0)).validate_privacy(&mut diag_sink);
}
_ => {}
}
for module in Package::all(&db).iter().flat_map(|pkg| pkg.modules(&db)) {
module.diagnostics(&db, &mut diag_sink);
}

drop(diag_sink);
Expand Down

0 comments on commit 6726db4

Please sign in to comment.