Commit a723fce7

a723fce724c1Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Struct members default to nil (nullable); box poly attr-writer values

A struct constructed with fewer args than members leaves the rest nil, so an under-supplied member is poly (nullable). Attr writers box the RHS when the backing ivar is poly.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
a723fce724c1
Parent
2dcc23b2faa9

src/analyze.cmodifiedView file

@@ -1138,8 +1138,9 @@
11381138 int args = nt_ref(nt, id, "arguments");
11391139 int an = 0;
11401140 const int *argv = args >= 0 ? nt_arr(nt, args, "arguments", &an) : NULL;
1141- for (int a = 0; a < an && a < cls->nivars; a++) {
1142- TyKind at = infer_type(c, argv[a]);
1141+ for (int a = 0; a < cls->nivars; a++) {
1142+ /* a member not supplied at this construction can be nil */
1143+ TyKind at = a < an ? infer_type(c, argv[a]) : TY_NIL;
11431144 TyKind m = ty_unify(cls->ivar_types[a], at);
11441145 if (m != cls->ivar_types[a]) { cls->ivar_types[a] = m; changed = 1; }
11451146 }