Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map[interface{}]interface{} entries are not properly rendered #12

Closed
kortschak opened this issue Jul 29, 2018 · 2 comments
Closed

map[interface{}]interface{} entries are not properly rendered #12

kortschak opened this issue Jul 29, 2018 · 2 comments

Comments

@kortschak
Copy link
Owner

The following code incorrectly hides non-repeated map entries.

package main

import "github.com/kortschak/utter"

func main() {
	a := map[interface{}][]interface{}{
		"examples": []interface{}{
			map[interface{}]interface{}{
				"a": []interface{}{"one-val"},
			},
			map[interface{}]interface{}{
				"b": []interface{}{"two-val"},
			},
		},
	}
	utter.Dump(a)
}

Output:

map[interface{}][]interface{}{
 string("examples"): []interface{}{
  map[interface{}]interface{}{
   string("a"): []interface{}(<already shown>),
  },
  map[interface{}]interface{}{
   string("b"): []interface{}(<already shown>),
  },
 },
}

go-spew handles this correctly, so I must have damaged something at some point.

@kortschak
Copy link
Owner Author

This is happening in dump.go +423 in the reflect.Slice case of the big switch and is happening because addr is 0 due to adding a zero pointer mark just after this when addr is zero from a previous non-pointer value. The fix is to only conditionally add pointer marks when addr is non-zero.

@kortschak
Copy link
Owner Author

It turns out there is a better fix and that this was due to the approach used in #5; in cases where the unpacked value is a []T, then you don't get an addr, so in that case use the address of the first element if it exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant