From 703a53cc04eb430a8d50dff8672d679617763f37 Mon Sep 17 00:00:00 2001 From: Felix <36384389+FelixDMxx@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:50:26 +0100 Subject: [PATCH] Fix floor division panic when only luau feature is enabled BinOp::DoubleSlash is available with the luau feature, but the trivia matches in trivia.rs and trivia_util.rs only handled it under lua53, so hanging a `//` expression or formatting one with comments around the operator panicked with "unknown node DoubleSlash" in luau-only builds. Fixes #1190 --- CHANGELOG.md | 4 ++++ src/formatters/trivia.rs | 2 +- src/formatters/trivia_util.rs | 6 ++++-- tests/inputs-luau/floor-division.lua | 5 +++++ tests/snapshots/tests__luau@floor-division.lua.snap | 8 +++++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac6dc18d..20b5c82b1 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 c5f63d83a..1110ef48c 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 2a103741a..71dc797ab 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 8460eebbd..15971c160 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 a6ba95031..2c2a598d1 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