--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that append arguments requirements are enforced by the
+// compiler.
+
+package main
+
+func main() {
+
+ s := make([]int, 8)
+
+ _ = append() // ERROR "missing arguments to append"
+ _ = append(s...) // ERROR "cannot use ... on first argument"
+ _ = append(s, 2, s...) // ERROR "too many arguments to append"
+
+}
cr = cs // ERROR "illegal types|incompatible|cannot"
cs = cr // ERROR "illegal types|incompatible|cannot"
+ var n int
+ <-n // ERROR "receive from non-chan"
+ n <- 2 // ERROR "send to non-chan"
+
c <- 0 // ok
<-c // ok
x, ok := <-c // ok
close(c)
close(cs)
close(cr) // ERROR "receive"
+ close(n) // ERROR "invalid operation.*non-chan type"
}
C128 Complex128
)
+func F1() int {
+ return 1
+}
+
+func F3() (int, int, int) {
+ return 1, 2, 3
+}
+
func main() {
// ok
c64 = complex(f32, f32)
_ = complex(f64, F64) // ERROR "complex"
_ = complex(F64, f64) // ERROR "complex"
+ _ = complex(F1()) // ERROR "expects two arguments.*returns 1"
+ _ = complex(F3()) // ERROR "expects two arguments.*returns 3"
+
+ _ = complex() // ERROR "missing argument"
+
c128 = complex(f32, f32) // ERROR "cannot use"
c64 = complex(f64, f64) // ERROR "cannot use"
C64 = complex(f32, f32) // ERROR "cannot use"
C128 = complex(f64, f64) // ERROR "cannot use"
+
}
_ = m[0][:] // ERROR "slice of unaddressable value"
_ = f()[:] // ERROR "slice of unaddressable value"
+ _ = 301[:] // ERROR "cannot slice"
+ _ = 3.1[:] // ERROR "cannot slice"
+ _ = true[:] // ERROR "cannot slice"
+
// these are okay because they are slicing a pointer to an array
_ = (&[3]int{1, 2, 3})[:]
_ = mp[0][:]
next *T
}
+type TP *T
+type Ti int
+
var (
_ = &T{0, 0, "", nil} // ok
_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
_ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal"
+ _ = TP{i: 0, f: 0, s: "", next: {}} // ERROR "invalid pointer type"
+ _ = &Ti{} // ERROR "invalid pointer type"
)
type M map[T]T
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that copy arguments requirements are enforced by the
+// compiler.
+
+package main
+
+func main() {
+
+ si := make([]int, 8)
+ sf := make([]float64, 8)
+
+ _ = copy() // ERROR "missing arguments"
+ _ = copy(1, 2, 3) // ERROR "too many arguments"
+
+ _ = copy(si, "hi") // ERROR "have different element types.*int.*string"
+ _ = copy(si, sf) // ERROR "have different element types.*int.*float64"
+
+ _ = copy(1, 2) // ERROR "must be slices; have int, int"
+ _ = copy(1, si) // ERROR "first argument to copy should be"
+ _ = copy(si, 2) // ERROR "second argument to copy should be"
+
+}
_ = funny([]T{}) // ok because []T{} is a T; passes []T{[]T{}}
)
+func Foo(n int) {}
+
func bad(args ...int) {
print(1, 2, args...) // ERROR "[.][.][.]"
println(args...) // ERROR "[.][.][.]"
_ = unsafe.Sizeof(x...) // ERROR "[.][.][.]"
_ = [...]byte("foo") // ERROR "[.][.][.]"
_ = [...][...]int{{1,2,3},{4,5,6}} // ERROR "[.][.][.]"
+
+ Foo(x...) // ERROR "invalid use of [.][.][.] in call"
}
var a3 = T { S{}, 2, 3, 4, 5, 6 } // ERROR "convert|too many"
var a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } // ERROR "index|too many"
var a5 = []byte { x: 2 } // ERROR "index"
+var a6 = []byte{1: 1, 2: 2, 1: 3} // ERROR "duplicate index"
var ok1 = S { } // should be ok
var ok2 = T { S: ok1 } // should be ok
e = E(t) // ok
t = T(e) // ERROR "need explicit|need type assertion|incompatible"
+
+ // cannot type-assert non-interfaces
+ f := 2.0
+ _ = f.(int) // ERROR "non-interface type"
+
}
type M interface {
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that make and new arguments requirements are enforced by the
+// compiler.
+
+package main
+
+func main() {
+ _ = make() // ERROR "missing argument"
+ _ = make(int) // ERROR "cannot make type"
+ _ = make([]int) // ERROR "missing len argument"
+
+ _ = new() // ERROR "missing argument"
+ _ = new(int, 2) // ERROR "too many arguments"
+}
package main
-func main() {}
-
type v bool
var (
type T6 struct { F T5 }
type T7 *T4
type T8 struct { F *T7 }
+
+func main() {
+ m := make(map[int]int)
+ delete() // ERROR "missing arguments"
+ delete(m) // ERROR "missing second \(key\) argument"
+ delete(m, 2, 3) // ERROR "too many arguments"
+ delete(1, m) // ERROR "first argument to delete must be map"
+}
\ No newline at end of file
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that recover arguments requirements are enforced by the
+// compiler.
+
+package main
+
+func main() {
+ _ = recover() // OK
+ _ = recover(1) // ERROR "too many arguments"
+ _ = recover(1, 2) // ERROR "too many arguments"
+}
w int64 = 1.0 << 33 // 1.0<<33 is a constant shift expression
_, _, _, _, _, _, _, _, _, _ = j, k, m, n, o, u, u1, u2, v, w
)
+
+ // non constants arguments trigger a different path
+ f2 := 1.2
+ s2 := "hi"
+ _ = f2 << 2 // ERROR "shift of type float64"
+ _ = s2 << 2 // ERROR "shift of type string"
}
// shifts in comparisons w/ untyped operands