Skip to content

[Enhancement] Improve Inline Object Type Literal Support #45

Description

@yhk1038

Summary

Currently, T-Ruby's inline object type literal ({ field: Type }) support is inconsistent across different contexts. This issue tracks the work to improve and unify this support.

Current Status

Context Status Example
Function parameters ✅ Supported def foo(config: { host: String, port: Integer })
Interface members ✅ Supported interface Config { settings: { debug: Boolean } }
Class fields ⚠️ Unverified @info: { name: String, age: Integer }
Variable declarations ❌ Not supported config: { host: String } = { ... }

Technical Details

Root Cause

The parse_typed_assignment() method in token_declaration_parser.rb:458 only accepts :constant tokens in the type position, preventing hash literal types from being parsed in variable declarations.

Affected Files

  • lib/t_ruby/parser_combinator/token/token_declaration_parser.rb
  • lib/t_ruby/ir.rb (HashLiteralType class at line 682)

Proposed Improvements

  1. Variable Declarations: Extend parse_typed_assignment() to call parse_type() instead of only accepting :constant tokens
  2. Class Fields: Add tests and documentation for @field: { ... } syntax
  3. Documentation: Update docs to clarify where inline object type literals are supported

Related

  • TypeScript equivalent: Object Type Literal / Anonymous Object Type
  • IR class: TRuby::IR::HashLiteralType

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions