Skip to content

reflect: StructOf allows creation of structs with invalid field names #20600

@dsnet

Description

@dsnet

Using Go1.8.3

t := reflect.StructOf([]reflect.StructField{
	reflect.StructField{Name: "", Type: reflect.TypeOf(0)},
	reflect.StructField{Name: "+", Type: reflect.TypeOf(0)},
})
fmt.Printf("%#v\n", reflect.New(t).Elem())

What did I see:
The creation of a struct with ridiculous field names.

struct { int; + int }{int:0, +:0}

What did I expect:
A panic of some sort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions