Skip to content

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

@ashurbekovz

Description

@ashurbekovz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions