← Back to Pull requests

codegen: fix type tags for `ifelse` with equal union branches #63384

Closed
unknown closed this pull request without merging on Sep 28, 2026 11:48 UTC
View on GitHub
unknown unknown commented on Sep 26, 2026 22:28 UTC
Author

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).

ifelse can return the wrong value when both branches are the same small union but the result is inferred as a wider one:

function f(c, v)
    y::Union{Int,Float64,Nothing} = nothing
    (() -> y = v[1])()
    return Core.ifelse(c, v[2], y)
end
v = Union{Int,Float64}[1, 2.5]
f(true, v)   # master: nothing   (expected 2.5)
f(false, v)  # master: 5.0e-324  (expected 1)

Plain Base.ifelse is affected too once the call has too many union members to be split. This ordinary do block is enough:

function b3(c, v)
    last::Union{eltype(v),Nothing} = nothing
    foreach((1,)) do i
        last = v[i]
    end
    return ifelse(c, v[2], last)
end
vm = Union{Missing,Int,Float64}[1, 2.5]
b3(true, vm), b3(false, vm)  # master: (nothing, 5.0e-324)

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.ifelse example | 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.ifelse on 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.

Diff: 298 lines (+223 / -75) across 3 files Reviewer: adienes Review duration: 2240m
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
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45% (MEDIUM) · Higher = larger blast radius
45%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.8% · Safe to merge
17.8%