Debian Codegraph @

go/analysis/passes/modernize/testdata/src/appendclipped/appendclipped.go

raw
1 package appendclipped
2
3 import (
4 "os"
5 "slices"
6 )
7
8 type (
9 Bytes []byte
10 Bytes2 []byte
11 )
12
13 func _(s, other []string) {
14 print(append([]string{}, s...)) // want "Replace append with slices.Clone"
15 print(append([]string(nil), s...)) // want "Replace append with slices.Clone"
16 print(append(Bytes(nil), Bytes{1, 2, 3}...)) // want "Replace append with slices.Clone"
17 print(append(other[:0:0], s...)) // want "Replace append with slices.Clone"
18 print(append(other[:0:0], os.Environ()...)) // want "Redundant clone of os.Environ()"
19 print(append(other[:0], s...)) // nope: intent may be to mutate other
20
21 print(append(append(append([]string{}, s...), other...), other...)) // want "Replace append with slices.Concat"
22 print(append(append(append([]string(nil), s...), other...), other...)) // want "Replace append with slices.Concat"
23 print(append(append(Bytes(nil), Bytes{1, 2, 3}...), Bytes{4, 5, 6}...)) // want "Replace append with slices.Concat"
24 print(append(append(append(other[:0:0], s...), other...), other...)) // want "Replace append with slices.Concat"
25 print(append(append(append(other[:0:0], os.Environ()...), other...), other...)) // want "Replace append with slices.Concat"
26 print(append(append(other[:len(other):len(other)], s...), other...)) // want "Replace append with slices.Concat"
27 print(append(append(slices.Clip(other), s...), other...)) // want "Replace append with slices.Concat"
28 print(append(append(append(other[:0], s...), other...), other...)) // nope: intent may be to mutate other
29 }
30
31 var (
32 _ Bytes = append(Bytes(nil), []byte(nil)...) // nope: correct fix requires Clone[Bytes] (#73661)
33 _ Bytes = append([]byte(nil), Bytes(nil)...) // nope: correct fix requires Clone[Bytes] (#73661)
34 _ Bytes2 = append([]byte(nil), Bytes(nil)...) // nope: correct fix requires Clone[Bytes2] (#73661)
35 )