Skip to content

Commit

Permalink
fix(service): fix checking folded if-condition when detecting unreach…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
g-plane committed Jan 8, 2025
1 parent 968b637 commit 055f2c3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/service/src/checker/unreachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ impl Checker<'_> {
}
}
Instr::Block(BlockInstr::If(block_if)) => {
block_if
.instrs()
.try_for_each(|instr| self.check_instr(&instr, parent_block, unreachable));
let if_branch = block_if
.then_block()
.is_some_and(|block| self.check_block_like(block.syntax()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: crates/service/tests/diagnostics/unreachable.rs
expression: response
---
{
"kind": "full",
"items": [
{
"range": {
"start": {
"line": 7,
"character": 6
},
"end": {
"line": 9,
"character": 13
}
},
"severity": 2,
"code": "unreachable",
"source": "wat",
"message": "unreachable code",
"tags": [
1
]
}
]
}
21 changes: 21 additions & 0 deletions crates/service/tests/diagnostics/unreachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,24 @@ fn folded_plain_instr() {
let response = service.pull_diagnostics(create_params(uri));
assert_json_snapshot!(response);
}

#[test]
fn folded_block_if() {
let uri = "untitled:test".parse::<Uri>().unwrap();
let source = "
(module
(func (param i32)
(if
(local.get 0)
(unreachable
(nop))
(nop)
(then)
(else))))
";
let mut service = LanguageService::default();
service.commit(uri.clone(), source.into());
disable_other_lints(&mut service, uri.clone());
let response = service.pull_diagnostics(create_params(uri));
assert_json_snapshot!(response);
}

0 comments on commit 055f2c3

Please sign in to comment.