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

proposal: spec: require tagged literals for external structs #2794

Open
robpike opened this issue Jan 27, 2012 · 6 comments

Comments

@robpike
Copy link
Contributor

commented Jan 27, 2012

It would aid compatibility and evolution if a package writer knew that all clients
creating structs with types exported from the package use the form
  pkg.Struct{A: a, B: b}
rather than
  pkg.Struct{a, b}

It may be worth making this a language restriction
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 2:

Not before Go 2.

Labels changed: added priority-someday, removed priority-later.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 3:

Labels changed: added repo-main.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2014

Comment 4:

Adding Release=None to all Priority=Someday bugs.

Labels changed: added release-none.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2014

Comment 5:

Labels changed: added go2, removed priority-someday.

@robpike robpike self-assigned this Mar 26, 2014

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

@robpike robpike removed their assignment Sep 21, 2015

@rsc rsc changed the title spec: require tagged literals for external structs proposal: spec: require tagged literals for external structs Jun 17, 2017

@dsnet dsnet added the Proposal label Jun 21, 2017

@dsnet dsnet modified the milestones: Proposal, Unplanned Jun 21, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2019

At present there is a vet check for this:

> go vet
b.go:5:9: pkg.Struct composite literal uses unkeyed fields

Is there an advantage to promoting this check to the language level?

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2019

There might be scenarios where it's tedious to have to repeat struct field names over and over again; e.g., for small structs that are frequently created and won't change. Example

p := graphic.Point3D{1, 2, 3}

But for cases like these it's always easy (and probably better) to provide any factory function instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.