Skip to content

Go structs with pointers to maps return unexpected type errors #533

@rorydbain

Description

@rorydbain

If I have a Go struct containing a pointer to a map, I'm unable to use that structure in Otto.

Here's an example test case:

func TestGoStructMapPointerField(t *testing.T) {
	type S struct {
		A *map[string]any `json:"a"`
	}

	tt(t, func() {
		test, vm := test()
		vm.Set("s", S{A: &map[string]any{
			"one": 1,
		}})

		test(`'a' in s`, true)
		test(`s.a.one`, 1)
	})
}

And the resulting error:

--- FAIL: TestGoStructMapPointerField (0.00s)
panic: TypeError: invalid value (map): missing runtime: map[one:1] (map[string]interface {}) [recovered]
	panic: TypeError: invalid value (map): missing runtime: map[one:1] (map[string]interface {}) [recovered]
	panic: TypeError: invalid value (map): missing runtime: map[one:1] (map[string]interface {}) [recovered]
	panic: TypeError: invalid value (map): missing runtime: map[one:1] (map[string]interface {})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions