Skip to content

Empty places in struct slice get filled with reference #61

@monstermichl

Description

@monstermichl

Empty places in struct slice get filled with reference. This means if an index gets set which is not yet available, all the indices prior to the set one get filled with the same reference to the default struct. Therefore, like shown in the example below, if an index in between gets set, all the other the other inserted index-places will hold the same value.

type easyStruct struct {
	a string
}

sl := []easyStruct{}
sl[2] = easyStruct{a: "Hello"}
sl[1].a = "World"

print(sl[0].a) // Results in "World".

This could be solved by either creating a completely new struct for each intermediate index or by just not assigning it at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions