From 0a69d2c7c1bf8e4675dbd1fe0cfd3a1774f8c02d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Mar 2026 06:48:47 +0000 Subject: [PATCH 1/2] fix: handle TypeInstantiation suffix in is_expression_simple (fixes #1088) When Luau turbofish syntax (e.g. `fn<>(args)`) appears inside a nested function call like `outer(function() return fn<>() end)`, the formatter calls `is_expression_simple` which iterates over suffixes of the inner function call. The `Suffix::TypeInstantiation` variant was not handled, causing an `unreachable!` panic. Add a `#[cfg(feature = "luau")]` arm to treat `TypeInstantiation` as a simple suffix (returns `true`), consistent with how it is handled in other suffix matches in the same file. https://claude.ai/code/session_01RYPhDsK1YMe3jU9n1SeKBE --- src/formatters/trivia_util.rs | 2 ++ tests/inputs-luau/type-instantiation-in-callback.lua | 4 ++++ ...ests__luau@type-instantiation-in-callback.lua.snap | 11 +++++++++++ 3 files changed, 17 insertions(+) create mode 100644 tests/inputs-luau/type-instantiation-in-callback.lua create mode 100644 tests/snapshots/tests__luau@type-instantiation-in-callback.lua.snap diff --git a/src/formatters/trivia_util.rs b/src/formatters/trivia_util.rs index 187ec80c..145cf577 100644 --- a/src/formatters/trivia_util.rs +++ b/src/formatters/trivia_util.rs @@ -156,6 +156,8 @@ fn is_expression_simple(expression: &Expression) -> bool { }, other => unreachable!("unknown node: {:?}", other), }, + #[cfg(feature = "luau")] + Suffix::TypeInstantiation(_) => true, other => unreachable!("unknown node: {:?}", other), }) } diff --git a/tests/inputs-luau/type-instantiation-in-callback.lua b/tests/inputs-luau/type-instantiation-in-callback.lua new file mode 100644 index 00000000..6831ea79 --- /dev/null +++ b/tests/inputs-luau/type-instantiation-in-callback.lua @@ -0,0 +1,4 @@ +-- Test for issue #1088: turbofish/TypeInstantiation inside nested function call +Charm.computed(function() + return createPluginSettingsStore<>("PresenceAuthStore", defaultValue, validate) +end) diff --git a/tests/snapshots/tests__luau@type-instantiation-in-callback.lua.snap b/tests/snapshots/tests__luau@type-instantiation-in-callback.lua.snap new file mode 100644 index 00000000..22011935 --- /dev/null +++ b/tests/snapshots/tests__luau@type-instantiation-in-callback.lua.snap @@ -0,0 +1,11 @@ +--- +source: tests/tests.rs +assertion_line: 36 +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau/type-instantiation-in-callback.lua +--- +-- Test for issue #1088: turbofish/TypeInstantiation inside nested function call +Charm.computed(function() + return createPluginSettingsStore<>("PresenceAuthStore", defaultValue, validate) +end) + From 449a8a0f471b2bff98fd4ad941dba105c9e0a69c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Mar 2026 19:53:45 +0000 Subject: [PATCH 2/2] docs: add changelog entry for #1088 turbofish panic fix https://claude.ai/code/session_01RYPhDsK1YMe3jU9n1SeKBE --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dfe9539..0fbe20f0 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 + +- Luau: Fixed panic when formatting explicit type instantiation (`f<>()`) inside a nested function call argument (e.g. as a callback) ([#1088](https://github.com/JohnnyMorganz/StyLua/issues/1088)) + ## [2.4.0] - 2026-03-07 ### Added