Semantic Diff

#9019 Fix a stack overflow on option of a recursive @unboxed variant

1 commit

d53b8ae6743e34997e61bf84f7166092a3d6ec56..pr-9019

fbd72f7e6 · cknitt + Claude · Oct 24, 2026, 12:09 UTC

Stop at recursion when checking whether a variant can be undefined

Why

Deciding whether option of a recursive @unboxed variant can be unboxed walked the payload types without remembering the variants it was in, so Recur(t) sent it into t forever and the compiler died with a stack overflow (#9018).

The walk remembers the variant declarations it is in. A variant met again adds no way to be undefined, since a value reaches undefined through finitely many unboxed payloads, so the answer comes from its other cases.

modifiedJS option of a recursive unboxed variant

@unboxed type rec t = Recur(t) | Endlet x: option<t> = Some(End)
js
Before
After
Fatal error: exception Stack overflowlet x = "End";

Fixes #9018