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

spec: type identity section not fully updated for 1.9 #22202

Closed
jiaweizhang opened this issue Oct 10, 2017 · 4 comments
Closed

spec: type identity section not fully updated for 1.9 #22202

jiaweizhang opened this issue Oct 10, 2017 · 4 comments
Milestone

Comments

@jiaweizhang
Copy link

jiaweizhang commented Oct 10, 2017

The Type identity (link) section of the doc has the following:

these types are identical:

A0, A1, and []string
A2 and struct{ a, b int }
A3 and int
A4, func(int, float64) *[]string, and A5

B0, B0, and C0
[]int and []int
struct{ a, b *T5 } and struct{ a, b *T5 }
func(x int, y float64) *[]string, func(int, float64) (result *[]string), and A5

B0 and B1 are different because they are new types created by distinct type definitions; func(int, float64) *B0 and func(x int, y float64) *[]string are different because B0 is different from []string.

Suggested fix

these types are identical:

A0, A1, and []string
A2, struct{ a, b int }
A3 and int
A4, func(A3, float64) *A0, func(x int, y float64) *[]string, func(int, float64) *[]string, and A5
B0 and C0

B0 and B1 are different because they are new types created by distinct type definitions. Similarly, func(int, float64) *B0 and func(x int, y float64) *A1 are different because B0 and A1 are created by distinct type definitions (A1 is an alias of []string while B0 is a new, distinct type with the same underlying type as []string.

Rationale

This section of the docs was not completely updated to reflect the addition of alias declarations. I also recommend moving the "Properties of types and values" section containing "Type identity" down under the "Declarations" (specifically "Type declarations"), so the concept of alias declarations is introduced before they are used.

@griesemer griesemer self-assigned this Oct 10, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 10, 2017
@griesemer
Copy link
Contributor

I don't see any issues here:

  • struct{a, b int} and struct{a, c int} are clearly different as they have different field names.
  • Yes B0 and C0 are identical but the list is meant to be exemplary, not exhaustive. Otherwise we'd have to add much more. What we have is correct.

Regarding ordering: It's difficult to come up with the "best order" in a language spec that is naturally recursive. Thanks for the suggestion, but for now I prefer leaving it as is, because a) there's hyperlinks that make it easy to jump around, and b) people got used to the current order.

Closing.

@jiaweizhang
Copy link
Author

The changes I made were more concerning the lines I took out:

[]int and []int
struct{ a, b *T5 } and struct{ a, b *T5 }

What exactly is the purpose of these two lines?

@griesemer
Copy link
Contributor

See #9226 for a discussion.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/87417 mentions this issue: spec: remove example explaining that type B0 and B0 are identical

gopherbot pushed a commit that referenced this issue Jan 11, 2018
Every few months we get a new error report claiming that there
is a typo in the spec related to this specific example. Clearly,
the fact that two types with the same identifier are identical
seems exceedingly obvious to readers; thus the example seems not
worth the trouble. Removing it.

For #9226.
For #22202.
For #22495.
For #23096.
For #23409.

There may be more.

Change-Id: I003ba79dc460ffb028a4ecb5f29efd60f2551912
Reviewed-on: https://go-review.googlesource.com/87417
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Rob Pike <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
@golang golang locked and limited conversation to collaborators Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants