From cf9ca6cb594e27237637bf15b00f9df8c5e11999 Mon Sep 17 00:00:00 2001 From: MALO <57839069+MDLC01@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:43:24 +0200 Subject: [PATCH] Fix compiler panic for float with no vertical alignment (#2437) --- crates/typst-library/src/layout/place.rs | 5 ++++- tests/typ/layout/place-float-auto.typ | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/typst-library/src/layout/place.rs b/crates/typst-library/src/layout/place.rs index 39a38b16d..64cbd9a88 100644 --- a/crates/typst-library/src/layout/place.rs +++ b/crates/typst-library/src/layout/place.rs @@ -95,7 +95,10 @@ impl Layout for PlaceElem { let float = self.float(styles); let alignment = self.alignment(styles); - if float && alignment.map_or(false, |align| align.y() == Some(VAlign::Horizon)) { + if float + && alignment + .map_or(false, |align| matches!(align.y(), None | Some(VAlign::Horizon))) + { bail!(self.span(), "floating placement must be `auto`, `top`, or `bottom`"); } else if !float && alignment.is_auto() { return Err("automatic positioning is only available for floating placement") diff --git a/tests/typ/layout/place-float-auto.typ b/tests/typ/layout/place-float-auto.typ index 799c9fc74..2ca3dc3ae 100644 --- a/tests/typ/layout/place-float-auto.typ +++ b/tests/typ/layout/place-float-auto.typ @@ -17,3 +17,15 @@ --- // Error: 2-45 floating placement must be `auto`, `top`, or `bottom` #place(center + horizon, float: true)[Hello] + +--- +// Error: 2-36 floating placement must be `auto`, `top`, or `bottom` +#place(horizon, float: true)[Hello] + +--- +// Error: 2-27 floating placement must be `auto`, `top`, or `bottom` +#place(float: true)[Hello] + +--- +// Error: 2-34 floating placement must be `auto`, `top`, or `bottom` +#place(right, float: true)[Hello]