diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac6dc18..20b5c82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed a panic when hanging a floor division (`//`) expression, or formatting one with comments around the operator, when only the `luau` feature is enabled ([#1190](https://github.com/JohnnyMorganz/StyLua/issues/1190)) + ## [2.6.0] - 2026-10-10 ### Added diff --git a/src/formatters/trivia.rs b/src/formatters/trivia.rs index c5f63d83..1110ef48 100644 --- a/src/formatters/trivia.rs +++ b/src/formatters/trivia.rs @@ -205,7 +205,7 @@ define_update_trivia!(BinOp, |this, leading, trailing| { TwoEqual, #[cfg(feature = "lua53")] Ampersand, - #[cfg(feature = "lua53")] + #[cfg(any(feature = "luau", feature = "lua53"))] DoubleSlash, #[cfg(feature = "lua53")] DoubleLessThan, diff --git a/src/formatters/trivia_util.rs b/src/formatters/trivia_util.rs index 2a103741..71dc797a 100644 --- a/src/formatters/trivia_util.rs +++ b/src/formatters/trivia_util.rs @@ -545,9 +545,10 @@ impl GetLeadingTrivia for BinOp { | BinOp::TildeEqual(token) | BinOp::TwoDots(token) | BinOp::TwoEqual(token) => GetLeadingTrivia::leading_trivia(token), + #[cfg(any(feature = "luau", feature = "lua53"))] + BinOp::DoubleSlash(token) => GetLeadingTrivia::leading_trivia(token), #[cfg(feature = "lua53")] BinOp::Ampersand(token) - | BinOp::DoubleSlash(token) | BinOp::DoubleLessThan(token) | BinOp::Pipe(token) | BinOp::DoubleGreaterThan(token) @@ -575,9 +576,10 @@ impl GetTrailingTrivia for BinOp { | BinOp::TildeEqual(token) | BinOp::TwoDots(token) | BinOp::TwoEqual(token) => GetTrailingTrivia::trailing_trivia(token), + #[cfg(any(feature = "luau", feature = "lua53"))] + BinOp::DoubleSlash(token) => GetTrailingTrivia::trailing_trivia(token), #[cfg(feature = "lua53")] BinOp::Ampersand(token) - | BinOp::DoubleSlash(token) | BinOp::DoubleLessThan(token) | BinOp::Pipe(token) | BinOp::DoubleGreaterThan(token) diff --git a/tests/inputs-luau/floor-division.lua b/tests/inputs-luau/floor-division.lua index 8460eebb..15971c16 100644 --- a/tests/inputs-luau/floor-division.lua +++ b/tests/inputs-luau/floor-division.lua @@ -1 +1,6 @@ local x = 1 // 2 +local column = (mousePosition.X - inventoryFrame.AbsolutePosition.X + scrollingFrame.CanvasPosition.X) // (SLOT_SIZE + SLOT_PADDING) +local y = a -- comment + // b +local z = a // -- comment + b diff --git a/tests/snapshots/tests__luau@floor-division.lua.snap b/tests/snapshots/tests__luau@floor-division.lua.snap index a6ba9503..2c2a598d 100644 --- a/tests/snapshots/tests__luau@floor-division.lua.snap +++ b/tests/snapshots/tests__luau@floor-division.lua.snap @@ -1,7 +1,13 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" input_file: tests/inputs-luau/floor-division.lua --- local x = 1 // 2 +local column = (mousePosition.X - inventoryFrame.AbsolutePosition.X + scrollingFrame.CanvasPosition.X) + // (SLOT_SIZE + SLOT_PADDING) +local y = a -- comment + // b +local z = a -- comment + // b