Files
hakorune/tools/hako_check/tests/HC015_arity_mismatch/expected.json
nyash-codex 501f791f61 Implement HC015: Arity Mismatch detection (MVP)
## Overview
Detects method calls with incorrect number of arguments (arity mismatch). MVP version focuses on clear `Box.method()` calls with wrong arity.

## Implementation Details
- **Rule**: `rule_arity_mismatch.hako` following box principles
- **Detection Method**: IR-based analysis using arity inference
  - Leverages `analysis_consumer.hako`'s `_infer_call_arity()` (already implemented)
  - Compares called arity vs. defined arity from methods[]
  - Reports mismatches as HC015 warnings
- **Integration**: Added to cli.hako in IR-based rules section

## Technical Approach
- **Arity Parsing**: Extracts arity from qualified names (`Box.method/arity`)
- **Method Lookup**: Searches methods[] for matching Box.method definition
- **Mismatch Detection**: Compares called arity vs. expected arity
- **MVP Scope**: Detects clear cases only (skips plugin/external methods if not found)

## Helper Methods
- `_parse_qualified()`: Parses `Box.method/arity` into components (MapBox result)
- `_find_method_arity()`: Searches methods[] for Box.method definition arity
- `_itoa()` / `_atoi()`: Integer conversion utilities

## Test Cases
- **ok.hako**: All calls match definitions
  - `Calculator.add(1, 2)` → matches `add/2`
  - `Helper.double(5)` → matches `double/1`
- **ng.hako**: Arity mismatches
  - `Calculator.add()` → expects `add/2`, got `add/0`
  - `Helper.double(1, 2)` → expects `double/1`, got `double/2`

## Test Results
```
[TEST/OK] HC011_dead_methods
[TEST/OK] HC012_dead_static_box
[TEST/OK] HC013_duplicate_method
[TEST/OK] HC014_missing_entrypoint
[TEST/OK] HC015_arity_mismatch ← NEW
[TEST/OK] HC016_unused_alias
[TEST/OK] HC017_non_ascii_quotes
[TEST/OK] HC018_top_level_local
[TEST/SUMMARY] all green
```

## Diagnostic Format
```
[HC015] arity mismatch: Box.method expects N arguments, got M :: Box.method/M
```

## Architecture
- Box-first design: RuleArityMismatchBox with single responsibility
- IR-based: Uses analysis_consumer's arity inference (no duplication)
- Clean separation: parsing, lookup, comparison, reporting

## Dependencies
- Relies on `analysis_consumer.hako`'s `_infer_call_arity()` implementation
- Fixed parser_core.hako arity bug (HC013 commit) ensures accuracy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 03:19:08 +09:00

5 lines
375 B
JSON

{"diagnostics":[
{"file":"ng.hako","line":1,"rule":"HC015","message":"[HC015] arity mismatch: Calculator.add expects 2 arguments, got 0 :: Calculator.add/0","quickFix":"","severity":"warning"},
{"file":"ng.hako","line":1,"rule":"HC015","message":"[HC015] arity mismatch: Helper.double expects 1 arguments, got 2 :: Helper.double/2","quickFix":"","severity":"warning"}
]}