Tested on gdscript-formatter 0.21.0 (Pre-release 0.21.0-beta, published 2026-07-12), Linux x86_64. Upstream main checked up to 248fa13b (2026-07-12 09:20 UTC) — no fix commit found.
Impact
When the resulting ] / as Array[T] sits at statement top (i.e. not inside enclosing parens), GDScript rejects as as an unexpected statement. When it happens to land inside enclosing parens / brackets it parses, but the shape is not idiomatic and is fragile against subsequent wrap decisions. The wrapper sometimes chooses to fold the array back to one very long line and wrap inside Array[ … ], which is also non-idiomatic.
Trigger
A typed-collection cast like [ ... ] as Array[T] where the array literal is already multi-line, or where the whole expression exceeds the max-line-length.
Repro
Input (bug.gd):
static func make_defs() -> Variant:
return [
SomeType.new(&"aaa"),
SomeType.new(&"bbb"),
SomeType.new(&"ccc"),
SomeType.new(&"ddd"),
] as Array[SomeType]
Command:
gdscript-formatter --stdout --reorder-code bug.gd
Actual output
static func make_defs() -> Variant:
return [
SomeType.new(&"aaa"),
SomeType.new(&"bbb"),
SomeType.new(&"ccc"),
SomeType.new(&"ddd"),
]
as Array[SomeType]
The ] and as Array[SomeType] end up on separate lines at the same indent level. Inside a return expression at function body indent this places as ... at statement top and GDScript rejects it (Parse Error: Expected statement, found "as" instead).
A related bad shape observed on longer inputs is as Array[ / SomeType / ] — the formatter folds the array back and wraps inside the Array[T] type parameter, which is also non-idiomatic even though it happens to parse.
Expected
Keep ] as Array[T] on the same line — wrap only the array elements while keeping ] as Array[T] contiguous. Never wrap inside the Array[T] type parameter, and never place as at statement top.
Tested on
gdscript-formatter 0.21.0(Pre-release0.21.0-beta, published 2026-07-12), Linux x86_64. Upstreammainchecked up to248fa13b(2026-07-12 09:20 UTC) — no fix commit found.Impact
When the resulting
] / as Array[T]sits at statement top (i.e. not inside enclosing parens), GDScript rejectsasas an unexpected statement. When it happens to land inside enclosing parens / brackets it parses, but the shape is not idiomatic and is fragile against subsequent wrap decisions. The wrapper sometimes chooses to fold the array back to one very long line and wrap insideArray[ … ], which is also non-idiomatic.Trigger
A typed-collection cast like
[ ... ] as Array[T]where the array literal is already multi-line, or where the whole expression exceeds the max-line-length.Repro
Input (
bug.gd):Command:
Actual output
The
]andas Array[SomeType]end up on separate lines at the same indent level. Inside areturnexpression at function body indent this placesas ...at statement top and GDScript rejects it (Parse Error: Expected statement, found "as" instead).A related bad shape observed on longer inputs is
as Array[/SomeType/]— the formatter folds the array back and wraps inside theArray[T]type parameter, which is also non-idiomatic even though it happens to parse.Expected
Keep
] as Array[T]on the same line — wrap only the array elements while keeping] as Array[T]contiguous. Never wrap inside theArray[T]type parameter, and never placeasat statement top.