Skip to content

Commit

Permalink
Fix parsing of select-with-results (#872)
Browse files Browse the repository at this point in the history
Previously multiple `(result)` blocks would erroneously discard the
previously parsed result blocks, so this commit fixes the textual
parsing of this instruction to collect all of the `(result)` blocks
instead of only the final one.

Closes #870
  • Loading branch information
alexcrichton committed Jan 5, 2023
1 parent edaf07e commit d79620f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/wast/src/core/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,18 +1872,20 @@ pub struct SelectTypes<'a> {

impl<'a> Parse<'a> for SelectTypes<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
let mut tys = None;
let mut found = false;
let mut list = Vec::new();
while parser.peek2::<kw::result>() {
let mut list = Vec::new();
found = true;
parser.parens(|p| {
p.parse::<kw::result>()?;
while !p.is_empty() {
list.push(p.parse()?);
}
Ok(())
})?;
tys = Some(list);
}
Ok(SelectTypes { tys })
Ok(SelectTypes {
tys: if found { Some(list) } else { None },
})
}
}
2 changes: 2 additions & 0 deletions tests/local/select-interesting.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(func (result i32) unreachable select (result i32) (result))
(func (result i32) unreachable select (result i32) (result) select)
12 changes: 12 additions & 0 deletions tests/snapshots/local/select-interesting.wat.print
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module
(type (;0;) (func (result i32)))
(func (;0;) (type 0) (result i32)
unreachable
select (result i32)
)
(func (;1;) (type 0) (result i32)
unreachable
select (result i32)
select
)
)

0 comments on commit d79620f

Please sign in to comment.