codegen: fix type tags for `ifelse` with equal union branches #63384
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 298 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.341
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #63384"
general
weight: 0.35
adienes
I asked claude to find bugs, with astra review.
Claude:
---
Found by a Claude Code (Opus 5.5) fuzzer comparing optimized runs against
--compile=min; the fix and this text were written by Claude Code too, and reviewed by Codex (gpt-6-astra).ifelsecan return the wrong value when both branches are the same small union but the result is inferred as a wider one:Plain
Base.ifelseis affected too once the call has too many union members to be split. This ordinarydoblock is enough:Codegen selects between the branches' type tags, which are relative to their own union, but labelled the result with the wider inferred type, so the tag was decoded against the wrong union. This labels the result, and computes any missing tags, against the branches' own union instead. By that point both branches always share that type, so cases that already worked are unchanged.
History
| | 1.9 to 1.13.0 | master |
| --- | --- | --- |
| example above (typed
y) | correct | wrong values || same without the annotation on
y| illegal instruction | illegal instruction ||
Base.ifelseexample | correct | wrong values |The underlying bug is old: when the inferred type is
Any, the mislabelled tag crashes on every release checked (1.9.4, 1.10.0, 1.10.12, 1.11.9, 1.12.1, 1.12.7, 1.13.0), hence the backport labels. On master it also started giving silently wrong values; the master change that exposed that has not been bisected yet (per-commit binaries no longer exist for that window, so it would need source builds).No affected package code was found: a GitHub code search found no package calling
Core.ifelseon union values, and a scan of compiled code for Base, DataFrames, CSV, Missings, StatsBase, Tables, PooledArrays and CategoricalArrays found no call of the affected shape.