feat(hotfix-8): Fix static method receiver detection logic (Hotfix 4 inversion bug)

## Issue
- StageBTraceBox.log("label") passed null for the label parameter
- Static methods incorrectly detected as having implicit receiver
- Hotfix 4 logic was inverted: `!matches!(params[0], MirType::Box(_))`

## Root Cause
src/mir/function.rs:90-101 had inverted logic:
- Instance methods (params[0]: Box type) → should have receiver
- Static methods (params[0]: non-Box type) → should NOT have receiver
- Previous code: `!matches!()` = true for non-Box → receiver=true (WRONG)

## Fix
- Changed `!matches!(signature.params[0], MirType::Box(_))` to
  `matches!(signature.params[0], MirType::Box(_))`
- Updated comments to clarify instance vs static method detection
- Result: static methods now correctly have receiver=0

## Verification
Before: fn='StageBTraceBox.log/1' params=1, receiver=1, total=2 
After:  fn='StageBTraceBox.log/1' params=1, receiver=0, total=1 

Test output:
Before: [stageb/trace]           # label=null
After:  [stageb/trace] test_label # label passed correctly 

## Files Changed
- src/mir/function.rs: Fixed has_implicit_receiver logic
- lang/src/compiler/entry/compiler_stageb.hako: Added guaranteed entry marker
  and direct print traces for Phase 25.1c debugging
- CURRENT_TASK.md: Updated task progress

## Phase 25.1c Progress
- Hotfix 8 完了:static method parameter passing 修正
- Stage-B トレース正常動作確認
- 次のタスク:ParserBox.parse_program2 ハング問題調査

🐾 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-19 05:30:31 +09:00
parent fa571a656e
commit dad278caf2
3 changed files with 84 additions and 23 deletions

View File

@ -77,26 +77,29 @@ impl MirFunction {
let mut blocks = HashMap::new();
blocks.insert(entry_block, BasicBlock::new(entry_block));
// 📦 Hotfix 1 + 4: Reserve ValueIds for function parameters at creation time
// 📦 Hotfix 1 + 4 + 8: Reserve ValueIds for function parameters at creation time
// Parameter ValueIds are %0, %1, ..., %N-1 where N = signature.params.len()
//
// 📦 Hotfix 4: Static method receiver reservation
// Static methods (e.g., Stage1UsingResolverFull.collect_entries/1) have implicit 'me' receiver
// that's not included in signature.params but needs ValueId reservation.
// 📦 Hotfix 8: Instance method receiver detection (Fixed Hotfix 4 logic inversion)
// - Instance methods (me.method()) have implicit 'me' receiver (params[0]: Box type)
// - Static methods (StaticBox.method()) have NO receiver (params[0]: non-Box type)
//
// Detection: If function name contains "." (box method or static method) AND
// params[0] is NOT a Box type → static method → needs +1 for receiver
// Detection: If function name contains "." (box method) AND
// params[0] IS a Box type → instance method → needs +1 for receiver
let param_count = signature.params.len() as u32;
let has_implicit_receiver = if signature.name.contains('.') {
// Box method or static method
// Box method (instance or static)
if signature.params.is_empty() {
// No params → static method with only receiver
true
// No params → static method with no receiver
// (e.g., StaticBox.method() with 0 params)
false
} else {
// Check if first param is Box type (instance method) or not (static method)
!matches!(signature.params[0], MirType::Box(_))
// ✅ FIXED: Instance method (Box type) → true, Static method (non-Box) → false
matches!(signature.params[0], MirType::Box(_))
}
} else {
// Global function → no receiver
false
};
@ -113,8 +116,15 @@ impl MirFunction {
}
if std::env::var("NYASH_LOOPFORM_DEBUG").is_ok() {
eprintln!("[MirFunction::new] fn='{}' params={}, receiver={}, total={}, initial_counter={}, pre_params={:?}",
signature.name, param_count, receiver_count, total_value_ids, initial_counter, pre_params);
eprintln!(
"[MirFunction::new] fn='{}' params={}, receiver={}, total={}, initial_counter={}, pre_params={:?}",
signature.name,
param_count,
receiver_count,
total_value_ids,
initial_counter,
pre_params
);
}
Self {