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

x/tools/gopls/internal/analysis/modernize: slicedelete: triggers on non idempotent slice identifiers #72955

Closed
ashurbekovz opened this issue Mar 19, 2025 · 1 comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ashurbekovz
Copy link

gopls version

x/tools/gopls v0.18.1

go env

irrelevant

What did you do?

This program prints [1 4]

package main

import (
	"fmt"
)

func main() {
	counter := 0
	getSlice := func() []int {
		counter++
		return []int{counter, counter + 1, counter + 2}
	}
	fmt.Println(append(getSlice()[:1], getSlice()[2:]...))
}

What did you see happen?

Gopls wants to modernize append(getSlice()[:1], getSlice()[2:]...) -> slices.Delete(getSlice(), 1, 2).
Since the two calls to getSlice() are replaced by one, the final output is replaced by [1 3].

What did you expect to see?

Behavior unchanged.

Editor and settings

No response

Logs

No response

@ashurbekovz ashurbekovz added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Mar 19, 2025
@gopherbot gopherbot added this to the Unreleased milestone Mar 19, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/659295 mentions this issue: gopls/internal/analysis/modernize: fix slicedelete triggers on non idempotent slice identifiers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
3 participants