feat: add Proc and Lambda type syntax for block parameters#38
Open
dfl wants to merge 7 commits intotype-ruby:mainfrom
Open
feat: add Proc and Lambda type syntax for block parameters#38dfl wants to merge 7 commits intotype-ruby:mainfrom
dfl wants to merge 7 commits intotype-ruby:mainfrom
Conversation
- Add Proc type parsing in TypeParser (Ruby-familiar syntax) - Proc(T) -> R maps to FunctionType and outputs ^(T) -> R in RBS - Fix type erasure to handle nested parentheses in complex types - Refactor erase_parameter_types for multi-line parameter handling Example: ```ruby def map(&block: Proc(Integer) -> String): Array<String> # block type erased in .rb output # outputs ^(Integer) -> String in .rbs end ``` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add block type signature to RBS method output: `{ (params) -> return }`
- Parse block parameters (`&block: Proc(T) -> R`) in Parser class
- Pass `kind` attribute through IR::Builder for block params
- Use `ir_type` from parser for proper FunctionType resolution
Example input:
def each(&block: Proc(Integer) -> void): void
RBS output:
def each: () { (Integer) -> void } -> void
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add IR::Yield node and visit_yield to CodeGenerator
- Add parse_yield to StatementParser for parsing yield statements
- Add check_yield_arguments to compiler type checking phase
- Validates yield argument count matches block parameter signature
Example error:
def each(&block: Proc(Integer, String) -> void)
yield 1 # Error: expects 2 arguments, but yield passes 1
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Parse &block? as optional block parameter
- Add `optional` attribute to IR::Parameter
- Generate ?{ } syntax in RBS for optional blocks
- Required blocks use { }, optional blocks use ?{ }
Example:
def maybe_yield(&block?: Proc(Integer) -> void): void
yield 1 if block_given?
end
RBS output:
def maybe_yield: () ?{ (Integer) -> void } -> void
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Lambda(T) -> R syntax alongside Proc(T) -> R - Add callable_kind attribute to FunctionType (:proc, :lambda, nil) - Add proc? and lambda? helper methods - Both convert to same RBS (^(T) -> R) since RBS doesn't distinguish - to_trb preserves the distinction for round-trip serialization Lambda enforces strict argument checking semantics (like Ruby's lambda), while Proc is more lenient (like Ruby's Proc). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Discussion #41 on going. |
Contributor
|
This will make close #34 |
Contributor
|
@dfl I just enabled CI workflow. Please check CI broken. |
Remove unnecessary double space before inline comment. Update Gemfile.lock for unicode-emoji 4.2.0.
Contributor
RuboCop Fix AppliedI've pushed a fix for the Change: - paren_depth = 1 # We're already past the opening paren
+ paren_depth = 1 # We're already past the opening paren@dfl Please cherry-pick commit f1f4955 or merge from |
# Conflicts: # Gemfile.lock # lib/t_ruby/ir.rb # lib/t_ruby/parser_combinator/type_parser.rb
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.
Summary
Proc(T) -> Rtype syntax for typed block parameters&block?)Test plan
🤖 Generated with Claude Code