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
- Variable Declarations: Extend
parse_typed_assignment() to call parse_type() instead of only accepting :constant tokens
- Class Fields: Add tests and documentation for
@field: { ... } syntax
- 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
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
def foo(config: { host: String, port: Integer })interface Config { settings: { debug: Boolean } }@info: { name: String, age: Integer }config: { host: String } = { ... }Technical Details
Root Cause
The
parse_typed_assignment()method intoken_declaration_parser.rb:458only accepts:constanttokens 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.rblib/t_ruby/ir.rb(HashLiteralType class at line 682)Proposed Improvements
parse_typed_assignment()to callparse_type()instead of only accepting:constanttokens@field: { ... }syntaxRelated
TRuby::IR::HashLiteralType