1// errorcheck
2
3// Copyright 2010 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// Verify that illegal uses of ... are detected.
8// Does not compile.
9
10package main
11
12import "unsafe"
13
14func sum(args ...int) int { return 0 }
15
16var (
17	_ = sum(1, 2, 3)
18	_ = sum()
19	_ = sum(1.0, 2.0)
20	_ = sum(1.5)      // ERROR "integer"
21	_ = sum("hello")  // ERROR ".hello. .type string. as type int|incompatible"
22	_ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
23)
24
25func sum3(int, int, int) int { return 0 }
26func tuple() (int, int, int) { return 1, 2, 3 }
27
28var (
29	_ = sum(tuple())
30	_ = sum(tuple()...) // ERROR "multiple-value|[.][.][.]"
31	_ = sum3(tuple())
32	_ = sum3(tuple()...) // ERROR "multiple-value|[.][.][.]" "not enough"
33)
34
35type T []T
36
37func funny(args ...T) int { return 0 }
38
39var (
40	_ = funny(nil)
41	_ = funny(nil, nil)
42	_ = funny([]T{}) // ok because []T{} is a T; passes []T{[]T{}}
43)
44
45func bad(args ...int) {
46	print(1, 2, args...)	// ERROR "[.][.][.]"
47	println(args...)	// ERROR "[.][.][.]"
48	ch := make(chan int)
49	close(ch...)	// ERROR "[.][.][.]"
50	_ = len(args...)	// ERROR "[.][.][.]"
51	_ = new(int...)	// ERROR "[.][.][.]"
52	n := 10
53	_ = make([]byte, n...)	// ERROR "[.][.][.]"
54	// TODO(rsc): enable after gofmt bug is fixed
55	//	_ = make([]byte, 10 ...)	// error "[.][.][.]"
56	var x int
57	_ = unsafe.Pointer(&x...)	// ERROR "[.][.][.]"
58	_ = unsafe.Sizeof(x...)	// ERROR "[.][.][.]"
59	_ = [...]byte("foo") // ERROR "[.][.][.]"
60	_ = [...][...]int{{1,2,3},{4,5,6}}	// ERROR "[.][.][.]"
61}
62
63