m is an unexported Field. fmt can not use interface() on the reflect values
to then call String on them on anything unexported or below.
This also happens if m is just interface{} and not a map:
https://play.golang.org/p/ODrjW3Fslf
If m is made an exported field by naming it M it works:
https://play.golang.org/p/Q1O31-XMBP
On Thursday, August 31, 2017 at 8:28:13 AM UTC+2, kortschak wrote:
>
> What is the expected behaviour for this code?
>
> https://play.golang.org/p/tp9YNQZRMo
>
> ```
> package main
>
> import (
> "fmt"
> )
>
> type char int
>
> func (c char) String() string { return string(c) }
>
> type st struct {
> m map[int]interface{}
> }
>
> func main() {
> a := char('A')
> s := st{map[int]interface{}{1: a}}
> fmt.Printf("%v %v", s, s.m)
> }
> ```
>
> I would expect both cases to print the `a` values as an 'A'.
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.