Repository navigation
Conversation
- Add TupleTypeExpression and TupleTypeElementExpression, parsed wherever a type is expected when it starts with `[`: `[string, integer]`, optional elements (`integer?`), a rest element (`...integer[]`), `[]`, nested tuples, and arrays of tuples (`[integer, integer][]`). - Flag a required element after an optional one, a rest element that is not last, and an optional rest element. - Tuple types transpile to `dynamic` (in typedefs too, the same as typed arrays) and are a BrighterScript-only feature. - Drop diagnostics produced by the speculative typed-assignment probe, so errors inside the type are not reported twice. - Add docs/tuples.md and a readme entry.
Contributor
|
Hey there! I just built a new temporary npm package based on 50406f5. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.57-1634-add-support-for-tuples.20261014134749.tgz |
`[string, ...integer[]]` resolved to `Array<string or Array<integer>>`; the rest element's array type is now unwrapped (through type aliases) to its item type, giving `Array<string or integer>`.
Contributor
|
Hey there! I just built a new temporary npm package based on c75143b. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.57-1634-add-support-for-tuples.20261014140215.tgz |
Copilot stopped reviewing on behalf of
iObject due to an error
October 14, 2026 14:08
The parser omits it in BrightScript mode, where a custom type name is skipped with its own diagnostic, so the field and constructor option now say so. Add a test that clones such an element.
Completions treated a position as a type only when the token was adjacent to `as`, so a name after `or`, `[`, or `,` (`string or Per|son`, `[Per|son, integer]`) offered runtime variables instead of types. Use the AST (util.isInTypeExpression) as well, which fixes unions and tuples.
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
…ples # Conflicts: # src/util.ts Co-authored-by: iObject <2446955+iObject@users.noreply.github.com>
Contributor
Merged the updated |
This branch has not been deployed
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.
Adds tuple types to BrighterScript (#1634): syntax, AST, diagnostics, transpilation, documentation, and editor support.
What this adds
A tuple type is an array with a fixed number of positions, each with its own type. The syntax matches TypeScript's and is accepted anywhere a type is expected: parameters, return types, typed assignments, typecasts,
typestatements, class fields, interface members, inline interfaces, and typed function types.Supported shapes:
[string, integer], including the empty tuple[][float, float, float?][string, ...integer[]][integer, integer][]), and unions inside or around a tupleNew diagnostics (all errors):
tuple-required-element-after-optional:[string?, integer]tuple-rest-element-must-be-last:[...string[], integer]tuple-rest-element-cannot-be-optional:[...string[]?]In
.brsfiles a tuple type gets the usualbs-feature-not-supportedwarning, anchored at the[.Typing
A tuple is typed as an array of its element types, so
[string, integer]isArray<string or integer>. A rest element contributes its item type (through type aliases), so[string, ...integer[]]and[string, ...Nums](wheretype Nums = integer[]) are bothArray<string or integer>. Type names inside a tuple are resolved and validated like any other type reference, so[Person, Missing]reportsCannot find name 'Missing'.Transpilation
A tuple is an ordinary
roArrayat runtime, so tuple types transpile todynamic, the same as typed arrays. This also applies to typedefs (type Pair = dynamic), matching how typed arrays and inline interfaces are already emitted there.Editor support
Hover, go-to-definition, and completions work on type names inside a tuple. Completions previously only treated a position as a type when the token was adjacent to
as, so a name afteror,[, or,offered runtime variables instead of type names. That was already broken for union types; completions now also useutil.isInTypeExpression, which fixes unions and tuples together.Implementation notes
tupleType()/tupleTypeElement()are called fromgetTypeExpressionPartwhen a type starts with[.consumeAsTokenAndTypeExpressionnow accepts[afteras, which is the one change that enables tuples in everyasposition. Before this PR[there was a parse error, so there is no conflict with array literals or indexing (both covered by tests).TupleTypeExpressionholdsTupleTypeElementExpressions; each element wraps aTypeExpressionplus optional...and?tokens.util.getTypeExpressionNamerenders them, soTypeExpression.getName()returns the written form. An element'stypeExpressionis optional because the parser omits it in BrightScript mode, where a custom type name is skipped with its own diagnostic.end suband the following functions as type names. Each ordering diagnostic is reported once and always has a location.x as <type> = valuespeculatively parses the type and backtracks, but previously kept any diagnostics from that attempt, so errors inside the type were reported twice. The probe now drops them. This also fixes the same latent duplication for inline interfaces.Tests
src/parser/tests/expression/TupleTypeExpression.spec.ts(33 tests): every shape and position above, each diagnostic with its exact location,.brsmode, error recovery and malformed elements, cloning (including an element with no type in.brsmode), typing of fixed and rest elements, typedefs, transpile output, type names resolving inside tuples, and hover / go-to-definition / completions on a type name inside a tuple.CompletionsProcessor.spec.tsgains a union + tuple completions test. Full suite: 5242 passing.Docs
New
docs/tuples.md(syntax, optional and rest elements, the three errors, transpilation, limitations) and an entry indocs/readme.md.Limitations
pair[0]) yields the union of its element types rather than the type at that position, and a tuple type is not checked for length or per-position compatibility against array literals or other tuples.readonly, and array literals are never inferred to be tuples (x = ["a", 1]isArray<string or integer>).[...string[], integer]) are not supported.(data as [string, integer])[0], the same as with typed arrays.