Skip to content

HashMap.remove lowers to raw presence flag instead of Option[V] #80

Closed

Description

@ehartford

Summary

HashMap.remove is lowered to the raw runtime presence flag instead of the surface return type Option[V].

This was split out of #78 after investigation showed it is not a receiver-shape bug and not specific to borrowed receivers.

Spec references:

  • docs/with-specification.md §7.7 method call syntax for self: &T / self: &mut T

Minimal repro

fn main:
    var map: HashMap[str, i32] = HashMap.new()
    map.insert("x", 9)
    assert(map.remove("x").unwrap() == 9)
    assert(map.len() == 0)

Expected

remove("x") should return Some(9), so .unwrap() yields 9 and the map length becomes 0.

Actual

The program fails at runtime because remove("x") is not materialized as an Option[i32] value.

The same bug is visible through borrowed receivers too:

let map_mut_ref = &mut map_mut
assert(map_mut_ref.remove("x").unwrap() == 9)

Root cause

Codegen for MIR_INTRINSIC_MAP_REMOVE in src/CodegenDispatch.w returns the raw result of with_hashmap_remove directly. That runtime function returns a found/present flag, not the removed value wrapped as Option[V].

By contrast, MIR_INTRINSIC_MAP_GET in the same file explicitly builds Option[V] from the runtime result.

Affected tests

  • test/behavior/issue64_borrowed_map_set_methods.w

Activity

  1. added a commit that references this issue on Jun 8, 2026
    a8bf4f6
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