Skip to content

Implicit-default return of HashMap/HashSet SEGFAULTs when the defaulted value is used #633

Closed

Description

@ehartford

Summary

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.

Found

Coverage sweep #492, 2026-07-03.

Activity

  1. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    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.

  2. ehartford commented on Jul 5, 2026

    @ehartford
    ContributorAuthor

    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.

  3. added a commit that references this issue on Jul 5, 2026
    cae01b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions