Skip to content

Conversation

@yhk1038
Copy link
Contributor

@yhk1038 yhk1038 commented Dec 24, 2025

Summary

  • Integrate TypeChecker into compiler to validate return type mismatches at compile time
  • Add type_check: true option to Compiler.new to enable validation
  • Fix TypeCheckError to properly inherit from StandardError for proper exception handling

Changes

  • lib/t_ruby/compiler.rb: Add type checking logic with check_types, check_method_return_type, types_compatible? methods
  • lib/t_ruby/type_checker.rb: Fix TypeCheckError to inherit from StandardError and avoid infinite recursion in to_s
  • spec/t_ruby/compiler_spec.rb: Add tests for type validation scenarios

Test plan

  • Type mismatch raises TypeCheckError (nil vs bool, String vs Integer)
  • Matching types pass without error
  • Type check is skipped when type_check: false (default)
  • Class methods are validated
  • All existing tests pass

Fixes #14

🤖 Generated with Claude Code

Add `type_check` option to Compiler that validates return types
at compile time. When enabled, the compiler infers method return
types using ASTTypeInferrer and compares them against declared
return type annotations. Raises TypeCheckError on mismatch.

Changes:
- Add type_check parameter to Compiler.new
- Integrate ASTTypeInferrer for return type inference
- Validate both top-level functions and class methods
- Support union types, nullable types, and subtype relationships
- Fix TypeCheckError to properly inherit from StandardError

Fixes #14
- Add type_check: true to DEFAULT_CONFIG in Config class
- Add Config#type_check? method to read the setting
- Compiler reads type_check? from config instead of parameter
- Remove redundant type_check parameter from Compiler.new
- CLI and Watcher use config-driven type checking
- Add type_check? mock to tests not testing type validation
- Normalize Boolean, TrueClass, FalseClass to bool in type comparison
- Disable type checking in E2E integration test (tests compilation, not types)
@yhk1038 yhk1038 merged commit a2be080 into main Dec 24, 2025
9 checks passed
@yhk1038 yhk1038 deleted the feature/integrate-typechecker branch December 24, 2025 06:15
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.

Integrate TypeChecker into compiler to validate return type mismatches

2 participants