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

Cannot update fields in elements of map[T1]*T2 #6

Closed
kortschak opened this issue Oct 10, 2017 · 2 comments
Closed

Cannot update fields in elements of map[T1]*T2 #6

kortschak opened this issue Oct 10, 2017 · 2 comments
Labels

Comments

@kortschak
Copy link

While map elements are not themselves addressable, if the element is a pointer the pointee should be modifiable directly via map access as shown in this playground snippet.

gomacro> import "reflect" // Just a package with a handy struct.
gomacro> m := make(map[string]*reflect.SliceHeader)
gomacro> m["a"] = &reflect.SliceHeader{}
gomacro> m["a"].Len = 2
repl.go:1:1: cannot assign to m["a"].Len
	repl.go:1:1: cannot take the address of a map element: m["a"]
@cosmos72
Copy link
Owner

cosmos72 commented Oct 11, 2017

confirmed, it's a bug.

The problem is not limited to maps - it happens with all syntaxes that return non-settable values which happen to be pointers. Another example:

gomacro> import "reflect"
gomacro> func header() *reflect.SliceHeader { return &reflect.SliceHeader{} }
gomacro> header().Len
0 // int
gomacro> header().Len = 2
repl.go:1:1: cannot assign to header().Len
        repl.go:1:1: cannot take the address of: header()

If you want to give a shot at it, I guess the problem is due to gomacro/fast/assignment.go method
(*Comp).placeOrAddress() not realizing that the implicit pointer dereference makes the expression addressable and settable.

Otherwise, I will probably be able to investigate it in 1-2 weeks (real life struck)

@cosmos72 cosmos72 added the bug label Oct 11, 2017
cosmos72 added a commit that referenced this issue Dec 6, 2017
The logic to handle this case was already present, but a stray check caused it to fail
@cosmos72
Copy link
Owner

cosmos72 commented Dec 6, 2017

Solved in commit 48c8420

@cosmos72 cosmos72 closed this as completed Dec 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants