Skip to content

fix(luau): preserve space after read/write modifier in array types#1127

Open
cschanhniem wants to merge 1 commit into
JohnnyMorganz:mainfrom
cschanhniem:fix/luau-array-access-modifier-space
Open

fix(luau): preserve space after read/write modifier in array types#1127
cschanhniem wants to merge 1 commit into
JohnnyMorganz:mainfrom
cschanhniem:fix/luau-array-access-modifier-space

Conversation

@cschanhniem

Copy link
Copy Markdown

The TypeInfo::Array formatter merges the access modifier (read/write) into the element type, changing code meaning. For example:

-- input
type A = { read Service }
-- output (before fix)
type A = { readService }
-- output (after fix)
type A = { read Service }

stylua --verify correctly detects the AST mismatch, but the formatter still produces the broken output.

Root cause

In src/formatters/luau.rs, the TypeInfo::Array arm formats the access token via format_token_reference without re-adding trailing trivia. The sibling format_type_field function handles this by calling .update_trailing_trivia(FormatTriviaType::Append(...)) with a space token.

Fix

  1. Singleline path: Append trailing space after the access token (matching format_type_field behavior)
  2. Multiline path: Place indent trivia on the access token instead of the element type (the current behavior puts indent between the modifier and the type, causing read\tService on a new line)

The multiline case also now positions the access token with proper leading indent for the multiline layout.

Fixes #1126

The TypeInfo::Array formatter merged the access modifier (read/write)
into the element type, changing code meaning. For example:
  `{ read Service }` formatted to `{ readService }`

This changes the singleline path to append trailing space after the
access token (matching what format_type_field already does), and the
multiline path to place the indent trivia on the access token rather
than the element type.

Fixes JohnnyMorganz#1126

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
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.

Luau: read/write modifier in array types merges into the element type, changing code meaning ({ read Foo } -> { readFoo })

1 participant