fix(mir/builder): clear metadata maps to prevent type pollution between static boxes
Root cause: When compiling multiple static boxes, metadata from using statements and previous box compilations (variable_map, value_origin_newbox, value_types) leaked into subsequent compilations, causing parameters to be incorrectly typed. For example, "args" parameter was incorrectly inferred as "ParserBox" instead of its actual type. Changes: 1. lifecycle.rs:95-97: Clear metadata before compiling each non-Main static box 2. decls.rs:42-44: Clear metadata before Phase 1 compilation in build_static_main_box 3. exprs.rs:170-172: Clear metadata before processing static box methods 4. builder_calls.rs:164-178: Add debug traces for value_origin_newbox/value_types Impact: - Fixes StageBArgsBox.resolve_src ValueId(21) undefined error - Prevents "ParserBox" type contamination of parameters - Ensures clean compilation context for each static box Note: Revealed new bug in StageBBodyExtractorBox (Copy from undefined ValueId(114)) which needs separate investigation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -87,6 +87,14 @@ impl super::MirBuilder {
|
||||
if name == "Main" {
|
||||
main_static = Some((name.clone(), methods.clone()));
|
||||
} else {
|
||||
// ✅ CRITICAL FIX: Clear metadata maps BEFORE compiling each static box
|
||||
// This prevents pollution from using statement resolution and previous boxes
|
||||
// from leaking into this box's method compilations.
|
||||
// Root cause: Using statements and previous box compilations create metadata
|
||||
// (variable_map, value_origin_newbox, value_types) that leaks into subsequent compilations.
|
||||
self.variable_map.clear();
|
||||
self.value_origin_newbox.clear();
|
||||
self.value_types.clear();
|
||||
// Lower all static methods into standalone functions: BoxName.method/Arity
|
||||
for (mname, mast) in methods.iter() {
|
||||
if let N::FunctionDeclaration { params, body, .. } = mast {
|
||||
|
||||
Reference in New Issue
Block a user