You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C emission references an undeclared constructor ID when a pure main exposes a datatype through a generic family field #1067
I returned a generic record from a pure main. The record's field type is a family that reduces to a user datatype at this instantiation.
import Base
type Inner is Data:
Inner{a: U32, b: U32}
def Pick(b: Bool) -> Data:
match b:
case False{}:
U32
case True{}:
Inner
type Box<-b: Bool> is Data:
Box{value: Pick(b)}
def main() -> Box<True{}>:
Box{Inner{1, 2}}
bun bend2/main.ts repro.bend
bun bend2/main.ts repro.bend -o out.js
bun out.js
bun bend2/main.ts repro.bend -o out.c
clang -std=c11 -O2 out.c -lpthread -lm -o out
What happened
The evaluator and emitted JS both accept the program and print the expected value:
Box{Inner{1, 2}}
Emitting C also exits successfully, but the generated source does not compile:
The generated declarations contain #define CID_BOX 13, but no definition for CID_INNER.
The same failure occurs when Inner has multiple constructors: SHOW_DESC references every hidden arm's CID, while none of those CID macros are declared.
Why it happens
compile_book computes the compiler reachability set before building the pure-main display descriptor. The generic Box field is seen as Pick(b) during reachability, so the concrete Inner datatype is not included among the constructors whose C IDs are emitted. show_main later reduces the concrete result type Box<True{}>, discovers Inner, and writes CID_INNER into SHOW_DESC anyway.
A direct Inner field makes the failure disappear because that separately roots its constructor ID. The failure therefore comes from disagreement between compilation reachability and the concrete type traversal used by show_main, rather than from the value itself.
Expected
A C file emitted successfully for an accepted program should compile and print the same Box{Inner{1, 2}} value as the evaluator and JS backend. Constructors referenced by the pure-main descriptor need to be included in the emitted CID table, including constructors reached only after reducing a family at a generic instantiation.
Environment
bend 2.0.27
commit 47bed75adedd6d6dd811721905f06569bf465f85
Bun 1.4.2
Darwin arm64
Apple clang version 21.0.0 (clang-2100.0.123.102)
Activity
Bend 2.0.32: the issue triage, root fixes, one verdict everywhere
VictorTaelin commentedon Sep 27, 2026
Fixed in Bend 2.0.32 (573002f): a pure main's printed datatypes are build roots, so a family field's datatype gets its constructor IDs.