-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: reporting "composite literal uses unkeyed fields" for slice types #9171
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
golang/go#9171 is closed as unfortunate, we will have to workaround this issue. This reverts commit 21bfa74.
I ignored all errors of the type "composite literal uses unkeyed fields". Most of them are wrong because of golang/go#9171.
Reports weird issues like: composite literal uses unkeyed fields See golang/go#9171
I ignored all errors of the type "composite literal uses unkeyed fields". Most of them are wrong because of golang/go#9171.
This is rather hacky but it should get rid of our last remaining go vet warning. This appears to be golang/go#9171, which was closed as "Unfortunate"
This is rather hacky but it should get rid of our last remaining go vet warning. This appears to be golang/go#9171, which was closed as "Unfortunate"
I had a conversation with a coworker (@tedsuo) about this today, we have this which doesn't pass vet, but that's really only possible with a slice literal, so I went and tried the following: // Check if the CompositeLit contains an unkeyed field.
allKeyValue := true
for _, e := range c.Elts {
if _, ok := e.(*ast.KeyValueExpr); !ok {
if cl, ok := e.(*ast.CompositeLit); !ok || cl.Type != nil {
allKeyValue = false
break
}
}
}
if allKeyValue {
return
} To detect composite literals with no type, seems like we can use that logic to not show this unfortunate warning on slice type aliases. |
Seems plausible. Sure, send a CL. |
CL https://golang.org/cl/22000 mentions this issue. |
We can trust that untyped composite literals are part of a slice literal and not emit a vet warning for those. Fixes #9171 Change-Id: Ia7c081e543b850f8be1fd1f9e711520061e70bed Reviewed-on: https://go-review.googlesource.com/22000 Run-TryBot: Rob Pike <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
CL https://golang.org/cl/22318 mentions this issue. |
- Simplified the code. - Removed types for slice aliases from composite literals' whitelist, since they are properly handled by vet. Fixes #15408 Updates #9171 Updates #11041 Change-Id: Ia1806c9eb3f327c09d2e28da4ffdb233b5a159b0 Reviewed-on: https://go-review.googlesource.com/22318 Run-TryBot: Rob Pike <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
The text was updated successfully, but these errors were encountered: