diff --git a/src/mir/builder/lifecycle.rs b/src/mir/builder/lifecycle.rs index 43b5116d..863f34e1 100644 --- a/src/mir/builder/lifecycle.rs +++ b/src/mir/builder/lifecycle.rs @@ -42,6 +42,27 @@ use crate::mir::join_ir::lowering::type_hint_policy::TypeHintPolicy; // Phase 67: P3-C ジェネリック型推論箱 use crate::mir::join_ir::lowering::generic_type_resolver::GenericTypeResolver; +// Phase 82: dev ガード用ヘルパー - Case 分類ロジック統一化 +// +// infer_type_from_phi_with_hint() の 2 つの callsite で重複していた +// Case 判定ロジックを DRY 化。 +// +// Case 分類: +// - Case A: hint 付き(GenericTypeResolver 不要) +// - Case B: P1/P2/P3-A/B で hint 失敗(理論上不可) +// - Case D: P3-C で GenericTypeResolver 失敗(PHI 走査フォールバック) +// +// Note: dev フラグで制御されるので、#[cfg] は不要(環境変数で制御) +fn classify_phi_fallback_case(hint: Option<&MirType>, function_name: &str) -> &'static str { + if hint.is_some() { + "Case A (hint付き)" + } else if TypeHintPolicy::is_target(function_name) { + "Case B (P1/P2/P3-A/B hint失敗)" + } else { + "Case D (P3-C GenericTypeResolver失敗)" + } +} + impl super::MirBuilder { /// Unified declaration indexing (Phase A): collect symbols before lowering /// - user_defined_boxes: non-static Box names (for NewBox birth() skip) @@ -319,13 +340,8 @@ impl super::MirBuilder { } // Phase 82: dev ガード - if_phi フォールバック禁止モード if crate::config::env::phi_fallback_disabled() { - let case = if hint.is_some() { - "Case A (hint付き)" - } else if TypeHintPolicy::is_target(&function.signature.name) { - "Case B (P1/P2/P3-A/B hint失敗)" - } else { - "Case D (P3-C GenericTypeResolver失敗)" - }; + let case = + classify_phi_fallback_case(hint.as_ref(), &function.signature.name); panic!( "[phase82/phi_fallback] disabled but infer_type_from_phi called\n\ Function: {}\n\ @@ -376,13 +392,8 @@ impl super::MirBuilder { } // Phase 82: dev ガード - if_phi フォールバック禁止モード if crate::config::env::phi_fallback_disabled() { - let case = if hint.is_some() { - "Case A (hint付き)" - } else if TypeHintPolicy::is_target(&function.signature.name) { - "Case B (P1/P2/P3-A/B hint失敗)" - } else { - "Case D (P3-C GenericTypeResolver失敗)" - }; + let case = + classify_phi_fallback_case(hint.as_ref(), &function.signature.name); panic!( "[phase82/phi_fallback] disabled but infer_type_from_phi called\n\ Function: {}\n\