fix: preserve parentheses for single-element type packs in explicit type instantiation#1090
Open
JohnnyMorganz wants to merge 2 commits intomainfrom
Open
fix: preserve parentheses for single-element type packs in explicit type instantiation#1090JohnnyMorganz wants to merge 2 commits intomainfrom
JohnnyMorganz wants to merge 2 commits intomainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1089.
Problem
f<<(number)>>(10)was incorrectly formatted tof<<number>>(10), stripping the parentheses from the single-element type pack. This changes the semantics:(number)is a type pack, whilenumberis a plain type — usingnumberwithout parentheses is a type error.Multi-element type packs like
(string, number)were unaffected becauseTypeInfo::Tuplewith multiple elements always keeps parentheses.Root Cause
format_type_instantiationcalledformat_type_infowith the default context (nowithin_genericflag). Thekeep_parenthesesfunction inluau.rsuseswithin_genericto 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 howformat_type_info_genericshandles regular generic type parameters likeFoo<(string)>.Test Plan
tests/inputs-luau/type-instantiation-type-pack.luawith the failing case from the issuef<<number>>(10)(parentheses stripped)f<<(number)>>(10)(parentheses preserved)cargo test --features luau