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: confusing example in map index expressions section #23895
Comments
Considering the map is declared as value type of V using T below is confusing. I would either remove the example entirely or change it to V. I don't see the added value in it's inclusion with respect to map indexing so I am suggesting it be removed. The both code snippets below will not compile. The top snippet because you can't store an int in a bool, the bottom because it considers ok an int which cannot be used in an if statement.
|
Change https://golang.org/cl/94906 mentions this issue: |
I don't think it is much confusing. The type |
@dotaheor, I see now. You are right, thank you. The This, for example, compiles and executes as expected: type mybool bool
m := make(map[string]mybool)
var v, ok mybool = m[""]
fmt.Println(v, ok) I believe issue can be closed then. |
The fourth example for map indexing states you have a map of type [K]V and attempts to read in a variable of type T. Further, the example is meant to showcase the boolean return variable saying whether the map contained a key, but overrides to type T. This will not compile. Changed last updated date to February 18 Fixes: #23895 Change-Id: I63c52adbcd989afd4855e329e6c727f4c01f7881 Reviewed-on: https://go-review.googlesource.com/94906 Reviewed-by: Robert Griesemer <gri@golang.org>
From index expressions section:
It seems like 4th example is only valid when
T
isbool
, which assumes that map havebool
as element value type.If this is correct, then
var v, ok T = a[x]
should be eithervar v, ok bool = a[x]
or re-phrased in other way (perhaps even removed).The text was updated successfully, but these errors were encountered: