## 実装内容
### HC012: Dead Static Box
- 未参照static boxを検出
- IR boxes配列活用、calls情報から参照チェック
- テスト: HC012_dead_static_box/{ok,ng}.hako + expected.json
### HC013: Duplicate Method
- 同名・同arityメソッド重複検出
- Box内でメソッド署名の一意性チェック
- テスト: HC013_duplicate_method/{ok,ng}.hako + expected.json
### 🔥 Critical Bug Fix: parser_core.hako arity計算修正
- **問題**: arityが「カンマの数」を返していた(add(a,b) → 1)
- **修正**: `if any == 1 { arity = arity + 1 }` に変更
- **影響**: 全メソッドのarity計算が正しくなった(HC015等に波及)
### Infrastructure改善
- analysis_consumer.hako: _ensure_array()ヘルパー導入
- MapBox.get().push()問題の根本解決
- uses/methods/calls/boxes全てで安全なpush実現
- run_tests.sh: NYASH_JSON_ONLY=1で出力純度確保
- cli.hako: HC012/HC013統合、デバッグ出力追加
## テスト結果
✅ HC011_dead_methods: OK
✅ HC012_dead_static_box: OK
✅ HC013_duplicate_method: OK
✅ HC016_unused_alias: OK
[TEST/SUMMARY] all green
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
66 lines
2.0 KiB
Plaintext
66 lines
2.0 KiB
Plaintext
// tools/hako_check/rules/rule_dead_static_box.hako — HC012: Dead Static Box
|
|
// Detect static boxes that are never referenced from any code path.
|
|
// Excludes Main box (entry point) and boxes referenced in calls.
|
|
|
|
using selfhost.shared.common.string_helpers as Str
|
|
|
|
static box RuleDeadStaticBoxBox {
|
|
method apply_ir(ir, path, out) {
|
|
local boxes = ir.get("boxes")
|
|
if boxes == null { return 0 }
|
|
|
|
local calls = ir.get("calls")
|
|
if calls == null { return 0 }
|
|
|
|
// Collect all box names that are referenced in calls
|
|
local referenced_boxes = new MapBox()
|
|
local ci = 0
|
|
while ci < calls.size() {
|
|
local call = calls.get(ci)
|
|
if call == null { ci = ci + 1; continue }
|
|
local to = call.get("to")
|
|
if to != null {
|
|
// Extract box name from qualified call (e.g., "Box.method/0" -> "Box")
|
|
local dot = to.indexOf(".")
|
|
if dot > 0 {
|
|
local box_name = to.substring(0, dot)
|
|
referenced_boxes.set(box_name, "1")
|
|
}
|
|
}
|
|
ci = ci + 1
|
|
}
|
|
|
|
// Check each box
|
|
local bi = 0
|
|
while bi < boxes.size() {
|
|
local box_info = boxes.get(bi)
|
|
if box_info == null { bi = bi + 1; continue }
|
|
|
|
local name = box_info.get("name")
|
|
if name == null { bi = bi + 1; continue }
|
|
|
|
local is_static = box_info.get("is_static")
|
|
|
|
// Skip Main box (entry point)
|
|
if name == "Main" { bi = bi + 1; continue }
|
|
|
|
// Only check static boxes
|
|
if is_static == null || is_static == 0 { bi = bi + 1; continue }
|
|
|
|
// Check if box is referenced - if not in map, it returns "[map/missing]" StringBox
|
|
local ref_check = referenced_boxes.get(name)
|
|
|
|
// If ref_check is null or doesn't equal "1", box is unreferenced
|
|
if ref_check == null || ref_check != "1" {
|
|
// Box is never referenced - report error
|
|
out.push("[HC012] dead static box (never referenced): " + name)
|
|
}
|
|
|
|
bi = bi + 1
|
|
}
|
|
return out.size()
|
|
}
|
|
}
|
|
|
|
static box RuleDeadStaticBoxMain { method main(args) { return 0 } }
|