1
0
mirror of https://github.com/golang/go synced 2024-11-27 03:31:29 -07:00
go/test/slice3err.go

122 lines
5.2 KiB
Go
Raw Normal View History

// errorcheck
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
var array *[10]int
var slice []int
var str string
var i, j, k int
func f() {
// check what missing arguments are allowed
_ = array[:]
_ = array[i:]
_ = array[:j]
_ = array[i:j]
_ = array[::] // ERROR "middle index required in 3-index slice|invalid slice indices" "final index required in 3-index slice"
_ = array[i::] // ERROR "middle index required in 3-index slice|invalid slice indices" "final index required in 3-index slice"
_ = array[:j:] // ERROR "final index required in 3-index slice|invalid slice indices"
_ = array[i:j:] // ERROR "final index required in 3-index slice|invalid slice indices"
_ = array[::k] // ERROR "middle index required in 3-index slice|invalid slice indices"
_ = array[i::k] // ERROR "middle index required in 3-index slice|invalid slice indices"
_ = array[:j:k]
_ = array[i:j:k]
_ = slice[:]
_ = slice[i:]
_ = slice[:j]
_ = slice[i:j]
_ = slice[::] // ERROR "middle index required in 3-index slice|invalid slice indices" "final index required in 3-index slice"
_ = slice[i::] // ERROR "middle index required in 3-index slice|invalid slice indices" "final index required in 3-index slice"
_ = slice[:j:] // ERROR "final index required in 3-index slice|invalid slice indices"
_ = slice[i:j:] // ERROR "final index required in 3-index slice|invalid slice indices"
_ = slice[::k] // ERROR "middle index required in 3-index slice|invalid slice indices"
_ = slice[i::k] // ERROR "middle index required in 3-index slice|invalid slice indices"
_ = slice[:j:k]
_ = slice[i:j:k]
_ = str[:]
_ = str[i:]
_ = str[:j]
_ = str[i:j]
_ = str[::] // ERROR "3-index slice of string" "middle index required in 3-index slice" "final index required in 3-index slice"
_ = str[i::] // ERROR "3-index slice of string" "middle index required in 3-index slice" "final index required in 3-index slice"
_ = str[:j:] // ERROR "3-index slice of string" "final index required in 3-index slice"
_ = str[i:j:] // ERROR "3-index slice of string" "final index required in 3-index slice"
_ = str[::k] // ERROR "3-index slice of string" "middle index required in 3-index slice"
_ = str[i::k] // ERROR "3-index slice of string" "middle index required in 3-index slice"
_ = str[:j:k] // ERROR "3-index slice of string"
_ = str[i:j:k] // ERROR "3-index slice of string"
// check invalid indices
_ = array[1:2]
_ = array[2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[2:2]
_ = array[i:1]
_ = array[1:j]
_ = array[1:2:3]
_ = array[1:3:2] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[2:1:3] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[2:3:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[3:1:2] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[3:2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[i:1:2]
_ = array[i:2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = array[1:j:2]
_ = array[2:j:1] // ERROR "invalid slice index|invalid slice indices"
_ = array[1:2:k]
_ = array[2:1:k] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[1:2]
_ = slice[2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[2:2]
_ = slice[i:1]
_ = slice[1:j]
_ = slice[1:2:3]
_ = slice[1:3:2] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[2:1:3] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[2:3:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[3:1:2] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[3:2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[i:1:2]
_ = slice[i:2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[1:j:2]
_ = slice[2:j:1] // ERROR "invalid slice index|invalid slice indices"
_ = slice[1:2:k]
_ = slice[2:1:k] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = str[1:2]
_ = str[2:1] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = str[2:2]
_ = str[i:1]
_ = str[1:j]
// check out of bounds indices on array
test: match gccgo error messages const1.go:33: error: integer constant overflow <similar errors omitted> const1.go:64: error: division by zero const1.go:67: error: floating point constant overflow const1.go:68: error: floating point constant overflow const1.go:69: error: floating point constant overflow const1.go:70: error: division by zero const1.go:71: error: expected integer type const1.go:77: error: argument 1 has incompatible type (cannot use type int8 as type int) const1.go:78: error: argument 1 has incompatible type (cannot use type int8 as type int) const1.go:79: error: argument 1 has incompatible type (cannot use type uint8 as type int) const1.go:81: error: argument 1 has incompatible type (cannot use type float32 as type int) const1.go:82: error: argument 1 has incompatible type (cannot use type float64 as type int) const1.go:83: error: floating point constant truncated to integer const1.go:85: error: argument 1 has incompatible type (cannot use type float64 as type int) const1.go:86: error: argument 1 has incompatible type (cannot use type string as type int) const1.go:87: error: argument 1 has incompatible type (cannot use type bool as type int) const1.go:90: error: const initializer cannot be nil const1.go:91: error: expression is not constant const1.go:92: error: expression is not constant const1.go:93: error: invalid constant type const1.go:94: error: invalid constant type fixedbugs/bug462.go:17: error: unknown field 'os.File' in 'T' fixedbugs/issue3705.go:9: error: cannot declare init - must be func fixedbugs/issue4251.go:12: error: inverted slice range fixedbugs/issue4251.go:16: error: inverted slice range fixedbugs/issue4251.go:20: error: inverted slice range fixedbugs/issue4405.go:11: error: invalid character 0x7 in identifier fixedbugs/issue4405.go:12: error: invalid character 0x8 in identifier fixedbugs/issue4405.go:13: error: invalid character 0xb in identifier fixedbugs/issue4405.go:14: error: invalid character 0xc in identifier fixedbugs/issue4429.go:15: error: expected pointer fixedbugs/issue4517d.go:9: error: cannot import package as init fixedbugs/issue4545.go:17: error: invalid context-determined non-integer type for left operand of shift fixedbugs/issue4545.go:16: error: incompatible types in binary expression fixedbugs/issue4610.go:15: error: expected ';' or '}' or newline fixedbugs/issue4610.go:16: error: expected declaration fixedbugs/issue4654.go:15: error: value computed is not used <similar errors omitted> fixedbugs/issue4776.go:9: error: program must start with package clause fixedbugs/issue4776.go:9: error: expected ';' or newline after package clause fixedbugs/issue4813.go:31: error: index must be integer <similar errors omitted> fixedbugs/issue4847.go:22: error: initialization expression for 'matchAny' depends upon itself fixedbugs/issue5089.go:13: error: redefinition of 'bufio.Buffered': receiver name changed fixedbugs/issue5089.go:11: note: previous definition of 'bufio.Buffered' was here fixedbugs/issue5172.go:17: error: reference to undefined field or method 'bar' fixedbugs/issue5172.go:18: error: reference to undefined field or method 'bar' fixedbugs/issue5172.go:12: error: use of undefined type 'bar' fixedbugs/issue5358.go:16: error: argument 2 has incompatible type fixedbugs/issue5581.go:29: error: use of undefined type 'Blah' funcdup.go:10: error: redefinition of 'i' funcdup.go:10: note: previous definition of 'i' was here <similar errors omitted> funcdup2.go:10: error: redefinition of 'i' funcdup2.go:10: note: previous definition of 'i' was here <similar errors omitted> slice3err.go:20: error: middle index required in 3-index slice <similar errors omitted> slice3err.go:20: error: final index required in 3-index slice <similar errors omitted> slice3err.go:21: error: final index required in 3-index slice slice3err.go:46: error: invalid 3-index slice of string <similar errors omitted> slice3err.go:57: error: inverted slice range <similar errors omitted> slice3err.go:62: error: invalid slice index: capacity less than length slice3err.go:64: error: invalid slice index: capacity less than start slice3err.go:65: error: invalid slice index: capacity less than start slice3err.go:66: error: invalid slice index: capacity less than start slice3err.go:68: error: invalid slice index: capacity less than length slice3err.go:70: error: invalid slice index: capacity less than start slice3err.go:80: error: invalid slice index: capacity less than length slice3err.go:82: error: invalid slice index: capacity less than start slice3err.go:83: error: invalid slice index: capacity less than start slice3err.go:84: error: invalid slice index: capacity less than start slice3err.go:86: error: invalid slice index: capacity less than length slice3err.go:88: error: invalid slice index: capacity less than start slice3err.go:99: error: array index out of bounds <similar errors omitted> slice3err.go:106: error: invalid slice index: capacity less than length slice3err.go:107: error: invalid slice index: capacity less than start slice3err.go:118: error: invalid slice index: capacity less than length slice3err.go:119: error: invalid slice index: capacity less than start syntax/semi1.go:10: error: missing '{' after if clause syntax/semi1.go:10: error: reference to undefined name 'x' syntax/semi1.go:10: error: reference to undefined name 'y' syntax/semi1.go:12: error: reference to undefined name 'z' syntax/semi2.go:10: error: missing '{' after switch clause syntax/semi2.go:10: error: reference to undefined name 'x' syntax/semi3.go:10: error: missing '{' after for clause syntax/semi3.go:10: error: reference to undefined name 'x' syntax/semi3.go:10: error: reference to undefined name 'y' syntax/semi3.go:10: error: reference to undefined name 'z' syntax/semi3.go:12: error: reference to undefined name 'z' syntax/semi4.go:11: error: missing '{' after for clause syntax/semi4.go:10: error: reference to undefined name 'x' syntax/semi4.go:12: error: reference to undefined name 'z' typecheck.go:12: error: reference to undefined name 'b' typecheck.go:17: error: reference to undefined name 'c' typecheck.go:11: error: use of undefined type 'b' typecheck.go:16: error: not enough arguments typecheck.go:17: error: not enough arguments R=golang-dev, rsc CC=golang-dev https://golang.org/cl/41520044
2013-12-12 18:18:12 -07:00
_ = array[11:11] // ERROR "out of bounds"
_ = array[11:12] // ERROR "out of bounds"
_ = array[11:] // ERROR "out of bounds"
_ = array[:11] // ERROR "out of bounds"
_ = array[1:11] // ERROR "out of bounds"
_ = array[1:11:12] // ERROR "out of bounds"
_ = array[1:2:11] // ERROR "out of bounds"
_ = array[1:11:3] // ERROR "out of bounds|invalid slice index"
_ = array[11:2:3] // ERROR "out of bounds|inverted slice|invalid slice index"
_ = array[11:12:13] // ERROR "out of bounds"
// slice bounds not checked
_ = slice[11:11]
_ = slice[11:12]
_ = slice[11:]
_ = slice[:11]
_ = slice[1:11]
_ = slice[1:11:12]
_ = slice[1:2:11]
_ = slice[1:11:3] // ERROR "invalid slice index|invalid slice indices"
_ = slice[11:2:3] // ERROR "invalid slice index|invalid slice indices|inverted slice"
_ = slice[11:12:13]
}