Russ Cox | 68796b0 | 2010-02-01 00:25:59 -0800 | [diff] [blame] | 1 | // errchk $G -e $D/$F.go |
| 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 | package main |
| 8 | |
Russ Cox | 75dd8fd | 2010-09-24 11:55:30 -0400 | [diff] [blame] | 9 | import "unsafe" |
| 10 | |
Russ Cox | 68796b0 | 2010-02-01 00:25:59 -0800 | [diff] [blame] | 11 | func sum(args ...int) int { return 0 } |
| 12 | |
| 13 | var ( |
| 14 | _ = sum(1, 2, 3) |
| 15 | _ = sum() |
| 16 | _ = sum(1.0, 2.0) |
| 17 | _ = sum(1.5) // ERROR "integer" |
Luuk van Dijk | e14d1d7 | 2011-12-14 17:34:35 +0100 | [diff] [blame^] | 18 | _ = sum("hello") // ERROR ".hello. .type string. as type int|incompatible" |
Luuk van Dijk | b536adb | 2011-10-08 19:37:06 +0200 | [diff] [blame] | 19 | _ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible" |
Russ Cox | 68796b0 | 2010-02-01 00:25:59 -0800 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | type T []T |
| 23 | |
| 24 | func funny(args ...T) int { return 0 } |
| 25 | |
| 26 | var ( |
| 27 | _ = funny(nil) |
| 28 | _ = funny(nil, nil) |
| 29 | _ = funny([]T{}) // ok because []T{} is a T; passes []T{[]T{}} |
| 30 | ) |
Russ Cox | 75dd8fd | 2010-09-24 11:55:30 -0400 | [diff] [blame] | 31 | |
| 32 | func bad(args ...int) { |
| 33 | print(1, 2, args...) // ERROR "[.][.][.]" |
| 34 | println(args...) // ERROR "[.][.][.]" |
| 35 | ch := make(chan int) |
| 36 | close(ch...) // ERROR "[.][.][.]" |
| 37 | _ = len(args...) // ERROR "[.][.][.]" |
Russ Cox | 75dd8fd | 2010-09-24 11:55:30 -0400 | [diff] [blame] | 38 | _ = new(int...) // ERROR "[.][.][.]" |
| 39 | n := 10 |
| 40 | _ = make([]byte, n...) // ERROR "[.][.][.]" |
| 41 | // TODO(rsc): enable after gofmt bug is fixed |
| 42 | // _ = make([]byte, 10 ...) // error "[.][.][.]" |
| 43 | var x int |
| 44 | _ = unsafe.Pointer(&x...) // ERROR "[.][.][.]" |
| 45 | _ = unsafe.Sizeof(x...) // ERROR "[.][.][.]" |
Anthony Martin | 5b62ba1 | 2011-05-31 15:41:47 -0400 | [diff] [blame] | 46 | _ = [...]byte("foo") // ERROR "[.][.][.]" |
Russ Cox | bf899be | 2011-07-26 00:52:02 -0400 | [diff] [blame] | 47 | _ = [...][...]int{{1,2,3},{4,5,6}} // ERROR "[.][.][.]" |
Russ Cox | 75dd8fd | 2010-09-24 11:55:30 -0400 | [diff] [blame] | 48 | } |
Russ Cox | bf899be | 2011-07-26 00:52:02 -0400 | [diff] [blame] | 49 | |