Think of something like this https://play.golang.org/p/GyPlYefS7ZW (maybe the example could be simpler) --> ok means we found the most nested value or the least one?
Le ven. 29 mars 2019 à 16:55, <jake6...@gmail.com> a écrit : > Yes, that is expected. The right hand side of the assignment is > `b[1].code`. That is a single value. The "magic" that allows a two value > return from a map lookup does not carry through to more complex expressions > that use the value from that lookup. It would get confusing really fast if > it did. > > On Friday, March 29, 2019 at 11:16:03 AM UTC-4, jlfo...@berkeley.edu > wrote: >> >> >> go version go1.12 linux/amd64 >> >> When compiling the example program below ( >> https://play.golang.org/p/koHORLMMuhK) >> I get the error >> >> assignment mismatch: 2 variable but 1 values >> >> for the assignment statement in Part 2 but the assignment statement in >> Part 1 compiles. >> Both assignment statements have the same number of values, but it appears >> that >> referencing an integer in a structure field in the 2nd assignment >> statement, rather than a simple >> integer, confuses the compiler. >> >> I know I can work around this problem by breaking Part 2 into 2 assignment >> statements, the first assigning a structure, and the second assigning the >> structure field, but >> I wonder if what I'm seeing is expected. >> >> Cordially, >> Jon Forrest >> >> --------------------------- >> >> package main >> >> import "fmt" >> >> var a = map[int]int{ >> 1: 2, >> } >> >> var b = map[int]Word{ >> 1: {2, 3}, >> } >> >> type Word struct { >> code int >> scratch int >> } >> >> func main() { >> var num int >> >> // Part 1 >> num, ok := a[1] >> if ok { >> fmt.Println(num) >> } >> >> // Part 2 >> num, ok = b[1].code // assignment mismatch: 2 variable but 1 >> values >> if ok { >> fmt.Println(num) >> } >> } >> >> >> -- > 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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.