Skip to content

reflect: SetMapIndex should not panic on a nil map delete #8051

@randall77

Description

@randall77
package main

import "reflect"

func main() {
    var m map[int]int
    delete(m, 5)
    
    v := reflect.ValueOf(m)
    v.SetMapIndex(reflect.ValueOf(5), reflect.Value{})
}

The first two lines succeed with no panic, as they should.
The second two lines panic with "delete from nil map".
They should silently succeed instead, like the non-reflect version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions