Skip to content
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

Cannot use fields of anonymous field in struct literal #164

Closed
gopherbot opened this issue Nov 14, 2009 · 3 comments
Closed

Cannot use fields of anonymous field in struct literal #164

gopherbot opened this issue Nov 14, 2009 · 3 comments
Labels
FrozenDueToAge LanguageChange Suggested changes to the Go language

Comments

@gopherbot
Copy link
Contributor

by kirklin.mcdonald:

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
@rsc
Copy link
Contributor

rsc commented Nov 14, 2009

Comment 1:

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

Labels changed: added language-change.

Owner changed to g...@golang.org.

@rsc
Copy link
Contributor

rsc commented Nov 14, 2009

Comment 2:

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 3:

This issue was closed by revision d3b1565.

Status changed to Fixed.

Merged into issue #-.

@bradfitz bradfitz added the LanguageChange Suggested changes to the Go language label Dec 17, 2014
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge LanguageChange Suggested changes to the Go language
Projects
None yet
Development

No branches or pull requests

4 participants