-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect: StructOf allows creation of structs with invalid field names #20600
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
Comments
If I'm allowed, I would like to work on it. Right now, it's only checking for an empty field name. ...
if field.Name == "" {
panic("reflect.StructOf: field " + strconv.Itoa(i) + " has no name")
}
... According to the language spec, a field name should be an identifier.
An extra check can be applied to make sure the field name matches the correct form. |
@pravj Please go ahead. Thanks. |
I've implemented a function to verify the field name and tested it, but I'm facing an issue following the contribution guideline. The
Sorry for starting the conversation here, as I wasn't able to make a change list because of this error. |
Just to be clear, this file |
@pravj if you can go into your $GOPATH/bin and remove gofmt then try again I think it should work. You can always rebuild with ./make.bash although that for some reason(but I was able to run it even before the rebuild), it didn't rebuild my gofmt so I built it like this: $ cd $GOPATH/src/go.googlesource.com/go/src/cmd/gofmt && go build -o $GOPATH/bin/gofmt and when ready run gofmt on your test, commit then you should be gucci to go! |
@odeke-em, I'm still getting the same error as I enter the Also, the cloned source (that I'm working with) shouldn't be in the $GOPATH as suggested in the contribution guide.
So I'm unable to digest the directory change you did to the source repo but inside $GOPATH. Didn't expect this while doing my first contribution, getting nervous. |
@pravj You need to build gofmt using the tip version of Go, not Go 1.8. The problem is that the future Go 1.9 adds a new language change: type aliases. You need to build a version of gofmt that uses the go/parse package from the future Go 1.9. |
CL https://golang.org/cl/45590 mentions this issue. |
Using Go1.8.3
What did I see:
The creation of a struct with ridiculous field names.
What did I expect:
A panic of some sort.
The text was updated successfully, but these errors were encountered: