diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fbe20f0..09183009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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)) +- Luau: Fixed parentheses being incorrectly removed from single-element type packs in explicit type instantiation, e.g. `f<<(number)>>(10)` becoming `f<>(10)` ([#1089](https://github.com/JohnnyMorganz/StyLua/issues/1089)) ## [2.4.0] - 2026-03-07 diff --git a/src/formatters/luau.rs b/src/formatters/luau.rs index bfc09dc5..39ee231a 100644 --- a/src/formatters/luau.rs +++ b/src/formatters/luau.rs @@ -1505,7 +1505,13 @@ pub fn format_type_instantiation( ) -> TypeInstantiation { let outer_arrows = format_contained_span(ctx, type_instantiation.outer_arrows(), shape); let inner_arrows = format_contained_span(ctx, type_instantiation.inner_arrows(), shape); - let types = format_punctuated(ctx, type_instantiation.types(), shape, format_type_info); + let context = TypeInfoContext::new().mark_within_generic(); + let types = format_punctuated( + ctx, + type_instantiation.types(), + shape, + |ctx, type_info, shape| format_type_info_internal(ctx, type_info, context, shape), + ); type_instantiation .to_owned() diff --git a/tests/inputs-luau/type-instantiation-type-pack.lua b/tests/inputs-luau/type-instantiation-type-pack.lua new file mode 100644 index 00000000..c62057cb --- /dev/null +++ b/tests/inputs-luau/type-instantiation-type-pack.lua @@ -0,0 +1,9 @@ +-- https://github.com/JohnnyMorganz/StyLua/issues/1089 + +local function f(...: T...) end + +f<<(number)>>(10) +f<<(string, number)>>(10, "a") + +local t = {} +t:method<<(number)>>(10) diff --git a/tests/snapshots/tests__luau@type-instantiation-type-pack.lua.snap b/tests/snapshots/tests__luau@type-instantiation-type-pack.lua.snap new file mode 100644 index 00000000..e11ec69a --- /dev/null +++ b/tests/snapshots/tests__luau@type-instantiation-type-pack.lua.snap @@ -0,0 +1,15 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau/type-instantiation-type-pack.lua +--- +-- https://github.com/JohnnyMorganz/StyLua/issues/1089 + +local function f(...: T...) end + +f<<(number)>>(10) +f<<(string, number)>>(10, "a") + +local t = {} +t:method<<(number)>>(10) +