You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code gives the following error:
$ cat test.go
package test
type A struct {
X int;
}
type B struct {
A;
Y int;
}
var b = B{X: 20, Y: 12}
$ 6g -o test.6 test.go
test.go:12: b.X undefined (type B has no field X)
Given that X is a valid field of B, I would expect this to be a valid
struct literal.
Additional information:
$ echo $GOARCH $GOOS
amd64 linux
$ hg log -l1
changeset: 4037:cd0140653802
The text was updated successfully, but these errors were encountered:
Struct literal syntax does not dig into embedded fields: the keys are field names, not
selectors. Instead, you can give a literal for the entire embedded structure:
var b = B{A:A{X:20}, Y:12}
This should probably be pointed out explicitly in
http://golang.org/doc/go_spec.html#Composite_literals
by kirklin.mcdonald:
The text was updated successfully, but these errors were encountered: