Files
hakorune/tools/hako_check/rules/rule_arity_mismatch.hako
nyash-codex 50ac8af2b8 Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks)
 Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback)
- Three-tier fallback system: plugin → builtin → core-ro
- Mode control: auto/plugin-only/core-ro
- New: src/box_factory/builtin_impls/file_box.rs
- New: tools/test_filebox_fallback_smoke.sh

 Task 2: Provider Registration SSOT (static/dynamic/core-ro unified)
- ProviderFactory trait with priority-based selection
- Global registry PROVIDER_FACTORIES implementation
- Priority: dynamic(100) > builtin(10) > core-ro(0)
- New: src/boxes/file/builtin_factory.rs
- New: tools/smoke_provider_modes.sh

 Task 3: FileBox Publication Unification
- Verified: basic/file_box.rs already minimized (11 lines)
- Perfect re-export pattern maintained

 Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority)
- Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS
- Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES
- Added deprecation warnings with migration guide
- ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE

 Task 5: Error Log Visibility (Analyzer rule execution errors to stderr)
- Added [rule/exec] logging before IR-based rule execution
- Format: [rule/exec] HC012 (dead_static_box) <filepath>
- VM errors now traceable via stderr output

 Task 6: Unnecessary Using Removal (14 rules Str alias cleanup)
- Removed unused `using ... as Str` from 14 rule files
- All rules use local _itoa() helper instead
- 14 lines of dead code eliminated

 Task 7: HC017 Skip & TODO Documentation (UTF-8 support required)
- Enhanced run_tests.sh with clear skip message
- Added "Known Limitations" section to README.md
- Technical requirements documented (3 implementation options)
- Re-enable timeline: Phase 22 (Unicode Support Phase)

📊 Test Results:
- Analyzer: 10 tests PASS, 1 skipped (HC017)
- FileBox fallback: All 3 modes PASS
- Provider modes: All 4 modes PASS
- Build: Success (0 errors, 0 warnings)

🎯 Key Achievements:
- 28 files modified/created
- Three-Tier Fallback System (stability)
- SSOT Provider Registry (extensibility)
- ENV unification (operational clarity)
- Error visibility (debugging efficiency)
- Code cleanup (maintainability)
- Comprehensive documentation (Phase 22 ready)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00

133 lines
3.6 KiB
Plaintext

// tools/hako_check/rules/rule_arity_mismatch.hako — HC015: Arity Mismatch (MVP)
// Detects method calls with incorrect number of arguments (arity mismatch).
// MVP version: detects clear Box.method() calls with wrong arity.
static box RuleArityMismatchBox {
method apply_ir(ir, path, out) {
local calls = ir.get("calls")
if calls == null { return 0 }
local methods = ir.get("methods")
if methods == null { return 0 }
// Check each call for arity mismatch
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 { ci = ci + 1; continue }
// to format: "Box.method/arity"
// Extract box, method, and called arity
local parts = me._parse_qualified(to)
if parts == null { ci = ci + 1; continue }
local box_name = parts.get("box")
local method_name = parts.get("method")
local called_arity = parts.get("arity")
// Find if a method with same box.method but different arity exists
local expected_arity = me._find_method_arity(methods, box_name, method_name)
if expected_arity < 0 {
// Method not found - could be external or plugin method, skip
ci = ci + 1
continue
}
// Check arity mismatch
if expected_arity != called_arity {
local msg = "[HC015] arity mismatch: " + box_name + "." + method_name
msg = msg + " expects " + me._itoa(expected_arity)
msg = msg + " arguments, got " + me._itoa(called_arity)
msg = msg + " :: " + to
out.push(msg)
}
ci = ci + 1
}
return out.size()
}
_find_method_arity(methods, box_name, method_name) {
// Search for method with given box.method prefix
// Returns arity if found, -1 if not found
local prefix = box_name + "." + method_name + "/"
local mi = 0
while mi < methods.size() {
local m = methods.get(mi)
if m != null {
if m.indexOf(prefix) == 0 {
// Extract arity from "Box.method/arity"
local slash_pos = m.lastIndexOf("/")
if slash_pos >= 0 {
local arity_str = m.substring(slash_pos + 1)
return me._atoi(arity_str)
}
}
}
mi = mi + 1
}
return -1
}
_parse_qualified(qualified) {
// Parse "Box.method/arity" into components
if qualified == null { return null }
local slash_pos = qualified.lastIndexOf("/")
if slash_pos < 0 { return null }
local arity_str = qualified.substring(slash_pos + 1)
local arity = me._atoi(arity_str)
local dot_pos = qualified.lastIndexOf(".")
if dot_pos < 0 { return null }
local box_name = qualified.substring(0, dot_pos)
local method_name = qualified.substring(dot_pos + 1, slash_pos)
local result = new MapBox()
result.set("box", box_name)
result.set("method", method_name)
result.set("arity", arity)
return result
}
_itoa(n) {
local v = 0 + n
if v == 0 { return "0" }
local out = ""
local digits = "0123456789"
local tmp = ""
while v > 0 {
local d = v % 10
tmp = digits.substring(d, d+1) + tmp
v = v / 10
}
out = tmp
return out
}
_atoi(s) {
if s == null { return 0 }
local n = s.length()
if n == 0 { return 0 }
local i = 0
local v = 0
local digits = "0123456789"
while i < n {
local ch = s.substring(i, i+1)
if ch < "0" || ch > "9" { break }
local pos = digits.indexOf(ch)
if pos < 0 { break }
v = v * 10 + pos
i = i + 1
}
return v
}
}
static box RuleArityMismatchMain { method main(args) { return 0 } }