fix(mir): Hotfix 6 - Instance method パラメータマッピング修正

問題:
- setup_method_params が next_value_id() を呼んで新しい ValueId を生成
- でも MirFunction::new() で既に ValueId 0..N が予約済み
- → パラメータが %2,%3 になり、シグネチャ %0,%1 とミスマッチ

修正:
- 予約済み ValueId を直接使用 (ValueId(0), ValueId(1), ...)
- setup_function_params と同じロジックに統一

影響:
- MyBox.birth/1 のパラメータマッピングが正しくなった
- %0 = me, %1 = v として正しく MIR 生成される

既知問題:
- user-defined box の実行時問題は残存(別調査が必要)
- dev verify の NewBox→birth 警告ロジック要調査

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-19 03:37:16 +09:00
parent b79697f137
commit c0fb1ccff8

View File

@ -7,6 +7,7 @@
use crate::ast::ASTNode;
use crate::mir::builder::{MirBuilder, MirType, MirInstruction};
use crate::mir::{ValueId};
use crate::mir::region::function_slot_registry::FunctionSlotRegistry;
use super::function_lowering;
use std::collections::HashMap;
@ -267,16 +268,18 @@ impl MirBuilder {
let mut slot_regs: Vec<(String, Option<MirType>)> = Vec::new();
if let Some(ref mut f) = self.current_function {
// First parameter is always 'me'
let me_id = f.next_value_id();
// 📦 Hotfix 6: Use pre-reserved ValueIds instead of generating new ones
// MirFunction::new() already reserved ValueIds 0..N for parameters
// First parameter is always 'me' at ValueId(0)
let me_id = ValueId(0);
f.params.push(me_id);
self.variable_map.insert("me".to_string(), me_id);
self.value_origin_newbox.insert(me_id, box_name.to_string());
slot_regs.push(("me".to_string(), None));
// Then regular parameters
for p in params {
let pid = f.next_value_id();
// Then regular parameters at ValueId(1), ValueId(2), ...
for (idx, p) in params.iter().enumerate() {
let pid = ValueId((idx + 1) as u32);
f.params.push(pid);
self.variable_map.insert(p.clone(), pid);
slot_regs.push((p.clone(), None));