Skip to content

Commit

Permalink
Fix newline separators between invalid end instructions (#1640)
Browse files Browse the repository at this point in the history
This commit fixes a bug from a prior refactoring where when there were
too many `end` instructions in a function, which is invalid, then
printing would confusingly "fuse" instructions together by not printing
a separator.
  • Loading branch information
alexcrichton authored Jun 27, 2024
1 parent 3f4960a commit 771b2bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/wasmprinter/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl<'printer, 'state, 'a, 'b> PrintOperator<'printer, 'state, 'a, 'b> {
fn block_end(&mut self) -> Result<()> {
if self.printer.nesting > self.nesting_start {
self.printer.nesting -= 1;
self.separator()?;
}
self.separator()?;
Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion tests/cli/print-no-panic-double-end.wat.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(module
(type (;0;) (func))
(func (;0;) (type 0)end)
(func (;0;) (type 0)
end
)
)
5 changes: 5 additions & 0 deletions tests/cli/print-with-too-many-ends.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;; RUN: print %

(module
(func end i32.const 0 drop end)
)
9 changes: 9 additions & 0 deletions tests/cli/print-with-too-many-ends.wat.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(module
(type (;0;) (func))
(func (;0;) (type 0)
end
i32.const 0
drop
end
)
)

0 comments on commit 771b2bd

Please sign in to comment.