Struct literals and embedding

245 views
Skip to first unread message

Josh Bleecher Snyder

unread,
Jun 20, 2013, 2:24:19 PM6/20/13
to golang-nuts
Can anyone give me some insight as to the design decision behind why you can't create a struct literal with direct references to embedded struct members?

See:


It feels (naively) to me like the second example there really ought to work.

Thanks!

-josh

Rob Pike

unread,
Jun 20, 2013, 2:32:54 PM6/20/13
to Josh Bleecher Snyder, golang-nuts
It might one day, but as it stands the requirement to provide more
information is more robust against changes in the data types.

-rob

Josh Bleecher Snyder

unread,
Jun 20, 2013, 4:36:28 PM6/20/13
to Rob Pike, golang-nuts
Makes sense. Thanks!

-josh

Kevin Gillette

unread,
Jun 20, 2013, 7:21:36 PM6/20/13
to golan...@googlegroups.com
Also note you can save a bit of redundant code by using type inference -- the main function code was modified in http://play.golang.org/p/SmeeROkVaa to demonstrate this.
Reply all
Reply to author
Forward
0 new messages