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

gopls/internal/analysis/modernize: fix slicedelete triggers on slice identifiers with side effects #567

Closed
Prev Previous commit
Next Next commit
fix formatting
ashurbekovz committed Mar 20, 2025
commit ba9d32a5eed49ed4832dbc67d60a9ccea2c74526
3 changes: 1 addition & 2 deletions gopls/internal/analysis/modernize/modernize.go
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ func enabledCategory(filter, category string) bool {
func isIdempotentExpr(expr ast.Expr) bool {
isDeterministic := true
ast.Inspect(expr, func(n ast.Node) bool {
switch n.(type) {
switch n.(type) {
case nil, *ast.Ident, *ast.BasicLit, *ast.BinaryExpr, *ast.UnaryExpr,
*ast.ParenExpr, *ast.SelectorExpr, *ast.IndexExpr, *ast.SliceExpr,
*ast.TypeAssertExpr, *ast.StarExpr, *ast.CompositeLit,
@@ -206,4 +206,3 @@ func isIdempotentExpr(expr ast.Expr) bool {
})
return isDeterministic
}

2 changes: 1 addition & 1 deletion gopls/internal/analysis/modernize/slicesdelete.go
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ func slicesdelete(pass *analysis.Pass) {

// equalSliceX checks that we're dealing with the same slice
func equalSliceX(slice1, slice2 *ast.SliceExpr) bool {
return equalSyntax(slice1.X, slice2.X) && isIdempotentExpr(slice1.X)
return equalSyntax(slice1.X, slice2.X) && isIdempotentExpr(slice1.X)
}

// Given two slice indices a and b, returns true if we can verify that a < b.