Source file test/sliceopt.go
1 // errorcheck -0 -d=append,slice 2 3 // Copyright 2015 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Check optimization results for append and slicing. 8 9 package main 10 11 func a1(x []int, y int) []int { 12 x = append(x, y) // ERROR "append: len-only update \(in local slice\)$" 13 return x 14 } 15 16 func a2(x []int, y int) []int { 17 return append(x, y) 18 } 19 20 func a3(x *[]int, y int) { 21 *x = append(*x, y) // ERROR "append: len-only update$" 22 } 23 24 func s1(x **[]int, xs **string, i, j int) { 25 var z []int 26 z = (**x)[0:] // ERROR "slice: omit slice operation$" 27 println(z) 28 29 var zs string 30 zs = (**xs)[0:] // ERROR "slice: omit slice operation$" 31 println(zs) 32 } 33