Re: [go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
Your answer has put me on the right track. Here's the long version: https://stackoverflow.com/questions/48790663/why-value-stored-in-an-interface-is-not-addressable-in-golang On Wednesday, April 24, 2024 at 6:55:53 PM UTC+2 cpu...@gmail.com wrote: > > In the first case, the interface contains

Re: [go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
> In the first case, the interface contains a value of type S, which is not writable. The value contained in the interface is not addressable. Thank you for the quick feedback. Why is that? Memory for val has been allocated and val is passed by value (hence copied). Why is that copy not be

Re: [go-nuts] Where is my type?

2024-04-24 Thread burak serdar
In the first case, the interface contains a value of type S, which is not writable. The value contained in the interface is not addressable. So Unmarshal creates a new map and fills that. In the second case the interface contains *S, which is writable, so unmarshal fills it in via reflection. On

[go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
Every time I feel I've come to terms with how Go works I round a corner and hit a wall, even after doing this for >5 years. Here's one. Consider this simple code (https://go.dev/play/p/bph5I80vc99): package main import ( "encoding/json" "fmt" ) type S struct { Foo int } func update(v any) {