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
Implicit-default return of HashMap/HashSet SEGFAULTs when the defaulted value is used #633
A function whose body falls through with return type HashMap[K,V] or HashSet[T] returns a defaulted value that SEGFAULTS on use (exit 139). HashMap.new().len() works, so the fault is in the implicit-default lowering, not HashMap itself.
Repro
fn d -> HashMap[str, i32]:
()
fn main:
print_i32(d().len() as i32) // exit 139
Spec §4.10
Implicit default return. Candidate: MirLower.w implicit-default path (~7440-7445) emits only void/bool/int defaults; str/Vec happen to work, HashMap/HashSet produce an invalid value. Either emit a proper empty-container default or reject implicit-default for these types.
BDFL ruling (2026-07-04): implicit default return must produce exactly the value .new()/default() produces — a real, fully usable empty container (avoiding Go's half-valid nil-map trap). §4.10 stays uniform across all Default types. Implementation: route the MirLower implicit-default path through the type's actual default constructor and AUDIT the whole table (str/Vec only 'happen to work' today); types without a valid default keep the existing 'return type does not implement Default' error.
Fixed in cae01b7. Implicit-default HashMap/HashSet now emit MAP_NEW (real empty containers) instead of a zeroed struct with null buckets; Vec emits VEC_NEW for byte-identity with Vec.new(). The repro (fn d -> HashMap[str,i32]: () then d().len()) returns 0 and .insert works — was exit 139. str/int/etc. keep their canonical zeroed default. Fixpoint + full suite green; 3 fixtures.
Activity
test: coverage-sweep batch 1 (#495 #496 #521 #518 #529 #492 #499)
ehartford commentedon Jul 4, 2026
BDFL ruling (2026-07-04): implicit default return must produce exactly the value
.new()/default()produces — a real, fully usable empty container (avoiding Go's half-valid nil-map trap). §4.10 stays uniform across all Default types. Implementation: route the MirLower implicit-default path through the type's actual default constructor and AUDIT the whole table (str/Vec only 'happen to work' today); types without a valid default keep the existing 'return type does not implement Default' error.docs: record BDFL soundness-tier rulings (2026-07-04)
ehartford commentedon Jul 5, 2026
Fixed in cae01b7. Implicit-default HashMap/HashSet now emit MAP_NEW (real empty containers) instead of a zeroed struct with null buckets; Vec emits VEC_NEW for byte-identity with Vec.new(). The repro (
fn d -> HashMap[str,i32]: ()thend().len()) returns 0 and.insertworks — was exit 139. str/int/etc. keep their canonical zeroed default. Fixpoint + full suite green; 3 fixtures.Fix #633: implicit-default HashMap/HashSet/Vec use real constructors …