Skip to content

Conversation

@yhk1038
Copy link
Contributor

@yhk1038 yhk1038 commented Jan 10, 2026

Summary

  • Add TypeScript-style array shorthand syntax String[] as an alternative to Array<String>
  • Both syntaxes produce identical IR and RBS output
  • Support nested arrays (Integer[][]), nullable arrays (String[]?), and arrays of nullable elements (String?[])

Changes

  • Add parse_postfix_type_operators method for handling [] and ? postfix operators
  • Update TokenDeclarationParser and TypeParser to support array shorthand syntax
  • Add 15 unit tests and 14 E2E tests
  • Update README examples (English, Korean, Japanese)

Examples

# Before (still works)
items: Array<String>

# After (new syntax)
items: String[]

# Nested arrays
matrix: Integer[][]

# Nullable array
cache: String[]?

# Array of nullable elements  
optional: String?[]

Test plan

  • bundle exec rspec spec/t_ruby/token_declaration_parser_spec.rb - 32 examples pass
  • bundle exec rspec spec/e2e/array_shorthand_spec.rb - 14 examples pass (2 pending)
  • bundle exec rspec - 3270 examples, 0 failures

- Add `String[]` as alternative to `Array<String>`
- Support nested arrays: `Integer[][]` → `Array[Array[Integer]]`
- Support nullable arrays: `String[]?` → `(Array[String] | nil)`
- Support arrays of nullable elements: `String?[]` → `Array[String?]`
- Support union type arrays: `(String | Integer)[]`
- Both syntaxes produce identical IR and RBS output
- Add parse_postfix_type_operators for `[]` and `?` suffix handling
- Add comprehensive unit tests (15 cases) and E2E tests (14 cases)
- Update README examples to show new syntax
Ruby 4.0 skips listen gem installation, but CI runs on Ruby 3.x which
requires it. Restore the original Gemfile.lock from main branch.
TypeParser now handles all type parsing including:
- Simple types, generics, array shorthand, union, intersection, function types

Remove legacy fallback code that was never executed, improving code coverage.
@yhk1038 yhk1038 merged commit c6a520f into main Jan 10, 2026
9 checks passed
@yhk1038 yhk1038 deleted the feature/improve-array-hash-tuple branch January 10, 2026 13:24
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.

2 participants