Skip to content

Propagate block return types to method return types#112

Open
dak2 wants to merge 1 commit intomainfrom
block-return-type-propagation
Open

Propagate block return types to method return types#112
dak2 wants to merge 1 commit intomainfrom
block-return-type-propagation

Conversation

@dak2
Copy link
Copy Markdown
Owner

@dak2 dak2 commented Apr 6, 2026

Motivation

Methods like map return generic types parameterized by block return values (e.g., [1,2].map { |x| x.to_s }Array[String]). Without this propagation, the type checker could not infer the element type of collections produced by block-yielding methods, causing false positives on subsequent method calls like .upcase.

Changes

  • Add BlockResult struct to return block body's last expression vertex from blocks.rs
  • Add BlockReturnTypeBox that observes block return type and substitutes type variables in method return types
  • Extend RbsTypeConverter::parse to handle generic types (e.g., Array[Elem], Hash[K, V])
  • Extract is_type_variable_name / is_block_type_variable_name as module-level functions and add resolve_return_type for shared type variable resolution
  • Remove unused SerializableMethodInfo::return_type() method (replaced by RbsTypeConverter::parse)

Checked

  • cargo test --lib passes
  • bundle exec rake test passes

🤖 Generated with Claude Code

Methods like `map` return generic types parameterized by block return values
(e.g., `[1,2].map { |x| x.to_s }` → `Array[String]`). Without this, the
type checker could not infer the element type of collections produced by
block-yielding methods, causing false positives on subsequent method calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 force-pushed the block-return-type-propagation branch from 8b77fcb to e1b6e44 Compare April 6, 2026 14:02
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.

1 participant