Skip to content

Nested arrays/structs using incorrect indices when initialising structs with keys #44

@chengda300

Description

@chengda300

Since the indices rely on the current instruction set, it assumes that it is sequential when we break it down to just the primitive data types.
Example: We have a type A struct.
type A struct { Name string Age int isMale bool Income float64 }
In the struct, Name is index 0, Age is index 1, isMale is index 2, Income is index 3.

Then in the case of array of structs, we can have:
[5]A{}
This gives us the following indices:
[0] Name: 0
[0] Age: 1
[0] isMale: 2
[0] Income: 3
[1] Name: 4
[1] Age: 5
...
[4] Income: 19

This will work, if we initialise each struct in sequence, since we can piggyback from the previous index and increment it directly.
However, in the case of keyed initialisation, sequence is not guaranteed, we can initialise Age/isMale/Income first instead of Name. Then, this piggybacking of indices will not work anymore.

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