diff --git a/src/mir/builder/calls/guard.rs b/src/mir/builder/calls/guard.rs index d6f93f19..0f07a5ad 100644 --- a/src/mir/builder/calls/guard.rs +++ b/src/mir/builder/calls/guard.rs @@ -59,11 +59,11 @@ impl<'a> CalleeGuardBox<'a> { { // Only apply guard if box_kind is StaticCompiler if box_kind == CalleeBoxKind::StaticCompiler { + let trace_enabled = + std::env::var("NYASH_CALLEE_RESOLVE_TRACE").ok().as_deref() == Some("1"); + // Check if receiver has a Box type if let Some(MirType::Box(receiver_box)) = self.value_types.get(&recv) { - let trace_enabled = - std::env::var("NYASH_CALLEE_RESOLVE_TRACE").ok().as_deref() == Some("1"); - // If receiver box type matches the static box name, this is a me-call // Let it through for static method lowering (don't normalize) if receiver_box == box_name { @@ -97,6 +97,20 @@ impl<'a> CalleeGuardBox<'a> { certainty, box_kind: CalleeBoxKind::RuntimeData, // Switch to runtime }); + } else { + // StaticCompiler Method but receiver has NO Box type + // → Pass through as ME-CALL (let downstream handle it) + if trace_enabled { + eprintln!("[static-runtime-guard] StaticCompiler receiver has NO Box type:"); + eprintln!( + " {}.{} receiver %{} has no type info", + box_name, method, recv.0 + ); + eprintln!(" → Passing through as ME-CALL (downstream will resolve)"); + } + + // Pass through unchanged - let finalize_method_receiver() handle it + return Ok(callee); } } } diff --git a/src/mir/builder/ssa/local.rs b/src/mir/builder/ssa/local.rs index 4770feb0..32ac533b 100644 --- a/src/mir/builder/ssa/local.rs +++ b/src/mir/builder/ssa/local.rs @@ -116,7 +116,13 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId builder.value_types.insert(loc, t); } if let Some(cls) = builder.value_origin_newbox.get(&v).cloned() { - builder.value_origin_newbox.insert(loc, cls); + builder.value_origin_newbox.insert(loc, cls.clone()); + + // CRITICAL FIX: For receiver kind, if type is missing but origin exists, + // infer MirType::Box from origin + if kind == LocalKind::Recv && builder.value_types.get(&loc).is_none() { + builder.value_types.insert(loc, crate::mir::MirType::Box(cls)); + } } builder.local_ssa_map.insert(key, loc); loc