-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: modernize slices.Clone suggestion wrong when copying between aliased types #73661
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
Related Issues Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Similar to #73663 , I will help to send a fix. Edit: according to go spec, If f is variadic with a final parameter p of type ...T, then within f the type of p is equivalent to type []T.. The named type |
@xieyuschen yeah, var b ssb = slices.Clone([]string(a)) And perhaps that's the way to go if this should remain a suggestion/fix for this particular case. |
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
Change https://go.dev/cl/671915 mentions this issue: |
|
func Clone[S ~[]E, E any](s S) S returns the However, the |
Change https://go.dev/cl/671975 mentions this issue: |
IMO the correct solution is to update the modernizer so that |
Whichever solution is merged, thank you both for jumping in here so quickly 👍 |
We've merged CLs; @anderseknert if you want to test the fix you could check out https://go-review.googlesource.com/c/tools/+/671915 and |
Thanks! |
@firelizzard18 I just tried to do that but I'm afraid I got stuck, as this workflow is new to me :) |
@anderseknert Gerrit doesn't use branches, at least not for CLs (which are roughly the equivalent to PRs). When you open the CL, there's a menu in the top-right (click Download Patch): Here's a copy of the first option. You can change
|
Thanks for those instructions, @firelizzard18 — much appreciated. I guess someone really looked at git and thought another layer of complexity was needed :) All good though, and I'm sure I'll learn to find my way around eventually. As for the issue, the simple example I provided with this issue seems to convert just fine now. However, the real-world code in OPA where I encountered this first seems to break still, although at least in a new and exciting way :P Screen.Recording.2025-05-19.at.21.33.38.movRepeating the location here for convenience in case you want to use it for a test: https://github.com/open-policy-agent/opa/blob/main/v1/ast/parser.go#L982 |
gopls version
v0.18.1
go env
What did you do?
Ran the modernize linter on this example:
What did you see happen?
What did you expect to see?
slices.Clone
not being suggested here, or at least not in a form that breaks compilation.The example is silly, but I encountered this in real code when trying to run modernize against the OPA project, here specifically.
Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: