Skip to content

fix: preserve parentheses for single-element type packs in explicit type instantiation#1090

Open
JohnnyMorganz wants to merge 2 commits intomainfrom
claude/fix-parentheses-preservation-P1dGj
Open

fix: preserve parentheses for single-element type packs in explicit type instantiation#1090
JohnnyMorganz wants to merge 2 commits intomainfrom
claude/fix-parentheses-preservation-P1dGj

Conversation

@JohnnyMorganz
Copy link
Owner

Fixes #1089.

Problem

f<<(number)>>(10) was incorrectly formatted to f<<number>>(10), stripping the parentheses from the single-element type pack. This changes the semantics: (number) is a type pack, while number is a plain type — using number without parentheses is a type error.

Multi-element type packs like (string, number) were unaffected because TypeInfo::Tuple with multiple elements always keeps parentheses.

Root Cause

format_type_instantiation called format_type_info with the default context (no within_generic flag). The keep_parentheses function in luau.rs uses within_generic to decide whether to strip parentheses from single-type tuples. Without this flag, (number)number.

Fix

Apply TypeInfoContext::new().mark_within_generic() when formatting types inside <<...>>, exactly mirroring how format_type_info_generics handles regular generic type parameters like Foo<(string)>.

Test Plan

  • Added tests/inputs-luau/type-instantiation-type-pack.lua with the failing case from the issue
  • Red: test failed showing f<<number>>(10) (parentheses stripped)
  • Green: after fix, test produces f<<(number)>>(10) (parentheses preserved)
  • Full test suite passes: cargo test --features luau

claude added 2 commits March 25, 2026 11:38
…ype instantiation

Fixes #1089. `f<<(number)>>(10)` was incorrectly formatted to `f<<number>>(10)`,
changing the semantics from a type pack to a plain type, which is a type error.

The fix applies `within_generic` context when formatting types inside `<<...>>`
type instantiation syntax, matching the same parentheses-preservation logic
used for generic type parameters (e.g. `Foo<(string)>`).

https://claude.ai/code/session_01TtJr824SDTbkw5ZEmYGQNm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit type instantiation syntax expects type packs, but StyLua formats out singular type packs

2 participants