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
encoding/json: panic: reflect.Set: value of type []uint8 is not assignable to type []main.Uint8 #12921
Comments
FWIW: This worked on go 1.4.2 |
Confirmed that it works under Go 1.4, so this is a regression. Not sure what to do about this, though, because you according to the language spec you can't assign |
@adg this problem only occurs with type uint8 https://golang.org/src/encoding/json/decode.go?s=#L749 example package main
import (
"encoding/json"
"fmt"
)
type MyType int8
func main() {
var sliceIn, sliceOut []MyType
for i := 0; i < 20; i++ {
sliceIn = append(sliceIn, MyType(i))
}
j, _ := json.Marshal(sliceIn)
json.Unmarshal(j, &sliceOut)
fmt.Printf("%#v\n", sliceOut)
} output
|
Well, that's weird. |
package main
import (
"encoding/json"
"fmt"
)
type Uint8 uint8
func main() {
var sliceIn []Uint8
for i := 0; i < 20; i++ {
sliceIn = append(sliceIn, Uint8(i))
}
j, _ := json.Marshal(sliceIn)
fmt.Println(string(j))
} output
|
I guess it's related to encoding/json's special handling of []byte. On 14 October 2015 at 09:04, Kirill Shvakov notifications@github.com
|
it seems that 4302fd0 ? |
Yeah, it's the fix to #8962 but it's debatable as to whether we fixed it in the right direction. |
CL https://golang.org/cl/16303 mentions this issue. |
I don't think it was introduced in encoding/json, just tried adding the same type declaration and managed to replicate it myself:
|
go version go1.5 darwin/amd64
go version go1.5.1 linux/amd64
output
http://play.golang.org/p/ZFlbNkI0H3
The text was updated successfully, but these errors were encountered: