diff options
| author | Robert Griesemer <gri@golang.org> | 2020-12-14 11:53:55 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2020-12-14 12:13:36 -0800 |
| commit | 91803a2df334ddfc9377ef4d07cc5f0eff51b6a2 (patch) | |
| tree | 277500790211cdab0ee3f12e1833efa44495afbc /test | |
| parent | a20021227e987a24d3dbac5118a9dee4d90a96ff (diff) | |
| parent | 89f38323faa57d3f7475016f778be69fcffbe9fb (diff) | |
| download | go-91803a2df334ddfc9377ef4d07cc5f0eff51b6a2.tar.xz | |
[dev.typeparams] merge: merge branch 'dev.regabi' into 'dev.typeparams'
The following files had merge conflicts and were merged manually:
src/cmd/compile/fmtmap_test.go
src/cmd/compile/internal/gc/noder.go
src/go/parser/error_test.go
test/assign.go
test/chan/perm.go
test/fixedbugs/issue22822.go
test/fixedbugs/issue4458.go
test/init.go
test/interface/explicit.go
test/map1.go
test/method2.go
The following files had manual changes to make tests pass:
test/run.go
test/used.go
src/cmd/compile/internal/types2/stdlib_test.go
Change-Id: Ia495aaaa80ce321ee4ec2a9105780fbe913dbd4c
Diffstat (limited to 'test')
38 files changed, 365 insertions, 76 deletions
diff --git a/test/assign.go b/test/assign.go index 549f42eb80..bdec58b710 100644 --- a/test/assign.go +++ b/test/assign.go @@ -42,7 +42,7 @@ func main() { _ = x } { - x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex|unknown field.* in struct literal" + x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex" _ = x } { @@ -56,13 +56,13 @@ func main() { { var x = 1 { - x, x := 2, 3 // ERROR "x repeated on left side of :=|x redeclared in this block" + x, x := 2, 3 // ERROR ".*x.* repeated on left side of :=|x redeclared in this block" _ = x } _ = x } { - a, a := 1, 2 // ERROR "a repeated on left side of :=|a redeclared in this block" + a, a := 1, 2 // ERROR ".*a.* repeated on left side of :=|a redeclared in this block" _ = a } } diff --git a/test/blank1.go b/test/blank1.go index 3c981cd5eb..815a7e9b5a 100644 --- a/test/blank1.go +++ b/test/blank1.go @@ -13,7 +13,7 @@ var t struct { _ int } -func (x int) _() { // ERROR "cannot define new methods on non-local type" +func (x int) _() { // ERROR "methods on non-local type" println(x) } diff --git a/test/chan/perm.go b/test/chan/perm.go index 607a356a02..4c94ab7ffa 100644 --- a/test/chan/perm.go +++ b/test/chan/perm.go @@ -25,8 +25,8 @@ func main() { cs = cr // ERROR "illegal types|incompatible|cannot" var n int - <-n // ERROR "receive from non-chan" - n <- 2 // ERROR "send to non-chan" + <-n // ERROR "receive from non-chan|expected channel" + n <- 2 // ERROR "send to non-chan|must be channel" c <- 0 // ok <-c // ok @@ -66,5 +66,5 @@ func main() { close(c) close(cs) close(cr) // ERROR "receive" - close(n) // ERROR "invalid operation.*non-chan type|not a channel" + close(n) // ERROR "invalid operation.*non-chan type|must be channel|not a channel" } diff --git a/test/complit1.go b/test/complit1.go index eb0f920fcb..7c2a4e2996 100644 --- a/test/complit1.go +++ b/test/complit1.go @@ -22,9 +22,9 @@ var ( _ = 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" + _ = 301[:] // ERROR "cannot slice|attempt to slice object that is not" + _ = 3.1[:] // ERROR "cannot slice|attempt to slice object that is not" + _ = true[:] // ERROR "cannot slice|attempt to slice object that is not" // these are okay because they are slicing a pointer to an array _ = (&[3]int{1, 2, 3})[:] @@ -46,8 +46,8 @@ 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 composite literal type TP" - _ = &Ti{} // ERROR "invalid composite literal type Ti" + _ = TP{i: 0, f: 0, s: "", next: {}} // ERROR "invalid composite literal type TP|omit types within composite literal" + _ = &Ti{} // ERROR "invalid composite literal type Ti|expected.*type for composite literal" ) type M map[T]T diff --git a/test/convlit.go b/test/convlit.go index de760542da..1c66c89e88 100644 --- a/test/convlit.go +++ b/test/convlit.go @@ -21,9 +21,9 @@ var x6 = int(1e100) // ERROR "overflow" var x7 = float32(1e1000) // ERROR "overflow" // unsafe.Pointer can only convert to/from uintptr -var _ = string(unsafe.Pointer(uintptr(65))) // ERROR "convert" -var _ = float64(unsafe.Pointer(uintptr(65))) // ERROR "convert" -var _ = int(unsafe.Pointer(uintptr(65))) // ERROR "convert" +var _ = string(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion" +var _ = float64(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion" +var _ = int(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion" // implicit conversions merit scrutiny var s string diff --git a/test/ddd1.go b/test/ddd1.go index 9857814648..01b9c0eadb 100644 --- a/test/ddd1.go +++ b/test/ddd1.go @@ -60,5 +60,5 @@ func bad(args ...int) { _ = [...]byte("foo") // ERROR "[.][.][.]" _ = [...][...]int{{1,2,3},{4,5,6}} // ERROR "[.][.][.]" - Foo(x...) // ERROR "invalid use of [.][.][.] in call" + Foo(x...) // ERROR "invalid use of .*[.][.][.]" } diff --git a/test/fixedbugs/bug176.go b/test/fixedbugs/bug176.go index ea3a909747..7001dd081e 100644 --- a/test/fixedbugs/bug176.go +++ b/test/fixedbugs/bug176.go @@ -9,6 +9,6 @@ package main var x int var a = []int{ x: 1} // ERROR "constant" -var b = [...]int{x: 1} +var b = [...]int{x: 1} // GCCGO_ERROR "constant" var c = map[int]int{ x: 1} diff --git a/test/fixedbugs/bug332.go b/test/fixedbugs/bug332.go index d43c2ddcff..159c8b4e68 100644 --- a/test/fixedbugs/bug332.go +++ b/test/fixedbugs/bug332.go @@ -14,4 +14,4 @@ func main() {} // important: no newline on end of next line. // 6g used to print <epoch> instead of bug332.go:111 -func (t *T) F() {} // ERROR "undefined: T"
\ No newline at end of file +func (t *T) F() {} // ERROR "undefined.*T"
\ No newline at end of file diff --git a/test/fixedbugs/bug340.go b/test/fixedbugs/bug340.go index a067940408..542a6eab03 100644 --- a/test/fixedbugs/bug340.go +++ b/test/fixedbugs/bug340.go @@ -13,6 +13,6 @@ func main() { switch t := x.(type) { case 0: // ERROR "type" t.x = 1 - x.x = 1 // ERROR "type interface \{\}|reference to undefined field or method" + x.x = 1 // ERROR "type interface \{\}|reference to undefined field or method|interface with no methods" } } diff --git a/test/fixedbugs/bug487.go b/test/fixedbugs/bug487.go index ab61a19a94..e60af6c8e2 100644 --- a/test/fixedbugs/bug487.go +++ b/test/fixedbugs/bug487.go @@ -14,8 +14,8 @@ func G() (int, int, int) { } func F() { - a, b := G() // ERROR "assignment mismatch" - a, b = G() // ERROR "assignment mismatch" + a, b := G() // ERROR "mismatch" + a, b = G() // ERROR "mismatch" _, _ = a, b } diff --git a/test/fixedbugs/bug510.dir/a.go b/test/fixedbugs/bug510.dir/a.go new file mode 100644 index 0000000000..db1cfef366 --- /dev/null +++ b/test/fixedbugs/bug510.dir/a.go @@ -0,0 +1,13 @@ +// Copyright 2020 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 a + +import "reflect" + +type A = map[int] bool + +func F() interface{} { + return reflect.New(reflect.TypeOf((*A)(nil))).Elem().Interface() +} diff --git a/test/fixedbugs/bug510.dir/b.go b/test/fixedbugs/bug510.dir/b.go new file mode 100644 index 0000000000..56b0201858 --- /dev/null +++ b/test/fixedbugs/bug510.dir/b.go @@ -0,0 +1,14 @@ +// Copyright 2020 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 main + +import "./a" + +func main() { + _, ok := a.F().(*map[int]bool) + if !ok { + panic("bad type") + } +} diff --git a/test/fixedbugs/bug510.go b/test/fixedbugs/bug510.go new file mode 100644 index 0000000000..8a6da5dfd6 --- /dev/null +++ b/test/fixedbugs/bug510.go @@ -0,0 +1,9 @@ +// rundir + +// Copyright 2020 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. + +// Gccgo confused type descriptors for aliases. + +package ignored diff --git a/test/fixedbugs/issue22822.go b/test/fixedbugs/issue22822.go index 554b534503..27c873ab10 100644 --- a/test/fixedbugs/issue22822.go +++ b/test/fixedbugs/issue22822.go @@ -11,7 +11,9 @@ package main func F() { slice := []int{1, 2, 3} - len := int(2) - println(len(slice)) // ERROR "cannot call non-function len .type int., declared at|cannot call non-function len" _ = slice + len := int(2) + println(len(slice)) // ERROR "cannot call non-function len .type int., declared at LINE-1|cannot call non-function len" + const iota = 1 + println(iota(slice)) // ERROR "cannot call non-function iota .type int., declared at LINE-1|cannot call non-function iota" } diff --git a/test/fixedbugs/issue28079b.go b/test/fixedbugs/issue28079b.go index 47cc16dfb2..9ff221baff 100644 --- a/test/fixedbugs/issue28079b.go +++ b/test/fixedbugs/issue28079b.go @@ -13,5 +13,5 @@ import "unsafe" type T [uintptr(unsafe.Pointer(nil))]int // ERROR "non-constant array bound" func f() { - _ = complex(1<<uintptr(unsafe.Pointer(nil)), 0) + _ = complex(1<<uintptr(unsafe.Pointer(nil)), 0) // ERROR "shift of type float64" } diff --git a/test/fixedbugs/issue4232.go b/test/fixedbugs/issue4232.go index 935f3820c6..30d132683a 100644 --- a/test/fixedbugs/issue4232.go +++ b/test/fixedbugs/issue4232.go @@ -19,7 +19,7 @@ func f() { _ = a[10:10] _ = a[9:12] // ERROR "invalid slice index 12|index out of bounds" _ = a[11:12] // ERROR "invalid slice index 11|index out of bounds" - _ = a[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" + _ = a[1<<100 : 1<<110] // ERROR "overflows int|integer constant overflow" "invalid slice index 1 << 100|index out of bounds" var s []int _ = s[-1] // ERROR "invalid slice index -1|index out of bounds" @@ -30,7 +30,7 @@ func f() { _ = s[10:10] _ = s[9:12] _ = s[11:12] - _ = s[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" + _ = s[1<<100 : 1<<110] // ERROR "overflows int|integer constant overflow" "invalid slice index 1 << 100|index out of bounds" const c = "foofoofoof" _ = c[-1] // ERROR "invalid string index -1|index out of bounds" @@ -41,7 +41,7 @@ func f() { _ = c[10:10] _ = c[9:12] // ERROR "invalid slice index 12|index out of bounds" _ = c[11:12] // ERROR "invalid slice index 11|index out of bounds" - _ = c[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" + _ = c[1<<100 : 1<<110] // ERROR "overflows int|integer constant overflow" "invalid slice index 1 << 100|index out of bounds" var t string _ = t[-1] // ERROR "invalid string index -1|index out of bounds" @@ -52,5 +52,5 @@ func f() { _ = t[10:10] _ = t[9:12] _ = t[11:12] - _ = t[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" + _ = t[1<<100 : 1<<110] // ERROR "overflows int|integer constant overflow" "invalid slice index 1 << 100|index out of bounds" } diff --git a/test/fixedbugs/issue42876.go b/test/fixedbugs/issue42876.go new file mode 100644 index 0000000000..67cf4919ac --- /dev/null +++ b/test/fixedbugs/issue42876.go @@ -0,0 +1,18 @@ +// run + +// Copyright 2020 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 main + +var x = [4]int32{-0x7fffffff, 0x7fffffff, 2, 4} + +func main() { + if x[0] > x[1] { + panic("fail 1") + } + if x[2]&x[3] < 0 { + panic("fail 2") // Fails here + } +} diff --git a/test/fixedbugs/issue42944.go b/test/fixedbugs/issue42944.go new file mode 100644 index 0000000000..bb947bc609 --- /dev/null +++ b/test/fixedbugs/issue42944.go @@ -0,0 +1,24 @@ +// errorcheck -0 -live + +// Copyright 2020 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. + +// Issue 42944: address of callee args area should only be short-lived +// and never across a call. + +package p + +type T [10]int // trigger DUFFCOPY when passing by value, so it uses the address + +func F() { + var x T + var i int + for { + x = G(i) // no autotmp live at this and next calls + H(i, x) + } +} + +func G(int) T +func H(int, T) diff --git a/test/fixedbugs/issue43099.go b/test/fixedbugs/issue43099.go new file mode 100644 index 0000000000..16f18e5f96 --- /dev/null +++ b/test/fixedbugs/issue43099.go @@ -0,0 +1,34 @@ +// compile + +// Copyright 2020 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. + +// Check to make sure we don't try to constant fold a divide by zero. +// This is a tricky test, as we need a value that's not recognized as 0 +// until lowering (otherwise it gets handled in a different path). + +package p + +func f() { + var i int + var s string + for i > 0 { + _ = s[0] + i++ + } + + var c chan int + c <- 1 % i +} + +func f32() uint32 { + s := "\x00\x00\x00\x00" + c := uint32(s[0]) | uint32(s[1])<<8 | uint32(s[2])<<16 | uint32(s[3])<<24 + return 1 / c +} +func f64() uint64 { + s := "\x00\x00\x00\x00\x00\x00\x00\x00" + c := uint64(s[0]) | uint64(s[1])<<8 | uint64(s[2])<<16 | uint64(s[3])<<24 | uint64(s[4])<<32 | uint64(s[5])<<40 | uint64(s[6])<<48 | uint64(s[7])<<56 + return 1 / c +} diff --git a/test/fixedbugs/issue4458.go b/test/fixedbugs/issue4458.go index 3ae9910d9e..6ac6d86db3 100644 --- a/test/fixedbugs/issue4458.go +++ b/test/fixedbugs/issue4458.go @@ -16,5 +16,5 @@ func (T) foo() {} func main() { av := T{} pav := &av - (**T).foo(&pav) // ERROR "no method foo|requires named type or pointer to named|undefined" + (**T).foo(&pav) // ERROR "no method .*foo|requires named type or pointer to named|undefined" } diff --git a/test/fixedbugs/issue5172.go b/test/fixedbugs/issue5172.go index 0339935b64..ed92ac6ff2 100644 --- a/test/fixedbugs/issue5172.go +++ b/test/fixedbugs/issue5172.go @@ -21,6 +21,6 @@ func main() { go f.bar() // ERROR "undefined" defer f.bar() // ERROR "undefined" - t := T{1} // ERROR "too many values" + t := T{1} // ERROR "too many" go t.Bar() } diff --git a/test/fixedbugs/issue6977.go b/test/fixedbugs/issue6977.go index 0f657eec41..4525e406b8 100644 --- a/test/fixedbugs/issue6977.go +++ b/test/fixedbugs/issue6977.go @@ -34,7 +34,7 @@ type U3 interface { M; m() } type U4 interface { M; M; M } type U5 interface { U1; U2; U3; U4 } -type U6 interface { m(); m() } // ERROR "duplicate method m" -type U7 interface { M32; m() } // ERROR "duplicate method m" -type U8 interface { m(); M32 } // ERROR "duplicate method m" -type U9 interface { M32; M64 } // ERROR "duplicate method m" +type U6 interface { m(); m() } // ERROR "duplicate method .*m" +type U7 interface { M32; m() } // ERROR "duplicate method .*m" +type U8 interface { m(); M32 } // ERROR "duplicate method .*m" +type U9 interface { M32; M64 } // ERROR "duplicate method .*m" diff --git a/test/init.go b/test/init.go index c2c25c7860..43bb3c6503 100644 --- a/test/init.go +++ b/test/init.go @@ -14,6 +14,6 @@ func init() { func main() { init() // ERROR "undefined.*init" - runtime.init() // ERROR "undefined.*runtime\.init|undefined: runtime" + runtime.init() // ERROR "undefined.*runtime\.init|reference to undefined name|undefined: runtime" var _ = init // ERROR "undefined.*init" } diff --git a/test/initializerr.go b/test/initializerr.go index 990ab60f96..5e2e9a91a0 100644 --- a/test/initializerr.go +++ b/test/initializerr.go @@ -23,7 +23,7 @@ var a2 = S { Y: 3, Z: 2, Y: 3 } // ERROR "duplicate" 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 a6 = []byte{1: 1, 2: 2, 1: 3} // ERROR "duplicate" var ok1 = S { } // should be ok var ok2 = T { S: ok1 } // should be ok diff --git a/test/interface/explicit.go b/test/interface/explicit.go index 7aaaad4e48..1b7af6712b 100644 --- a/test/interface/explicit.go +++ b/test/interface/explicit.go @@ -47,7 +47,7 @@ func main() { t = i // ERROR "incompatible|assignment$" i = i2 // ok - i2 = i // ERROR "incompatible|missing N method|cannot convert" + i2 = i // ERROR "incompatible|missing N method" i = I(i2) // ok i2 = I2(i) // ERROR "invalid|missing N method|cannot convert" @@ -57,7 +57,7 @@ func main() { // cannot type-assert non-interfaces f := 2.0 - _ = f.(int) // ERROR "non-interface type|not an interface type" + _ = f.(int) // ERROR "non-interface type|only valid for interface types|not an interface type" } @@ -100,10 +100,7 @@ type T2 struct{} func (t *T2) M() {} func (t *T2) _() {} -// Check that nothing satisfies an interface with blank methods. -// Disabled this test as it's not clear we need this behavior. -// See also issue #42964. -/* -var b1 B1 = &T2{} // "incompatible|missing _ method" -var b2 B2 = &T2{} // "incompatible|missing _ method" -*/
\ No newline at end of file +// Already reported about the invalid blank interface method above; +// no need to report about not implementing it. +var b1 B1 = &T2{} +var b2 B2 = &T2{} diff --git a/test/label.go b/test/label.go index 11716cc2c5..7deead6fba 100644 --- a/test/label.go +++ b/test/label.go @@ -61,5 +61,5 @@ L10: goto L10 - goto go2 // ERROR "label go2 not defined" + goto go2 // ERROR "label go2 not defined|reference to undefined label .*go2" } diff --git a/test/label1.go b/test/label1.go index b2e0ef09b8..a8eaecbff2 100644 --- a/test/label1.go +++ b/test/label1.go @@ -15,11 +15,11 @@ var x int func f1() { switch x { case 1: - continue // ERROR "continue is not in a loop$" + continue // ERROR "continue is not in a loop$|continue statement not within for" } select { default: - continue // ERROR "continue is not in a loop$" + continue // ERROR "continue is not in a loop$|continue statement not within for" } } @@ -103,14 +103,14 @@ L5: } } - continue // ERROR "continue is not in a loop$" + continue // ERROR "continue is not in a loop$|continue statement not within for" for { - continue on // ERROR "continue label not defined: on" + continue on // ERROR "continue label not defined: on|invalid continue label .*on" } - break // ERROR "break is not in a loop, switch, or select" + break // ERROR "break is not in a loop, switch, or select|break statement not within for or switch or select" for { - break dance // ERROR "break label not defined: dance" + break dance // ERROR "break label not defined: dance|invalid break label .*dance" } for { diff --git a/test/linkname2.go b/test/linkname2.go new file mode 100644 index 0000000000..43e66a5849 --- /dev/null +++ b/test/linkname2.go @@ -0,0 +1,30 @@ +// errorcheck + +// Copyright 2020 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. + +// Tests that errors are reported for misuse of linkname. +package p + +import _ "unsafe" + +type t int + +var x, y int + +//go:linkname x ok + +// ERROR "//go:linkname requires linkname argument or -p compiler flag" +// BAD: want error "//go:linkname must refer to declared function or variable" +// BAD: want error "//go:linkname must refer to declared function or variable" +// ERROR "duplicate //go:linkname for x" + +// The two BAD lines are just waiting for #42938 before we can +// re-enable the errors. + +//line linkname2.go:18 +//go:linkname y +//go:linkname nonexist nonexist +//go:linkname t notvarfunc +//go:linkname x duplicate diff --git a/test/live.go b/test/live.go index 3df7ab01af..d52ce7f007 100644 --- a/test/live.go +++ b/test/live.go @@ -718,5 +718,5 @@ func f44(f func() [2]*int) interface{} { // ERROR "live at entry to f44: f" } ret := T{} ret.s[0] = f() - return ret // ERROR "stack object .autotmp_5 T" + return ret // ERROR "stack object .autotmp_[0-9]+ T" } diff --git a/test/map1.go b/test/map1.go index bd4d87b871..a6b27e6ebd 100644 --- a/test/map1.go +++ b/test/map1.go @@ -64,5 +64,5 @@ func main() { delete() // ERROR "missing arguments|not enough arguments" delete(m) // ERROR "missing second \(key\) argument|not enough arguments" delete(m, 2, 3) // ERROR "too many arguments" - delete(1, m) // ERROR "first argument to delete must be map|is not a map" -}
\ No newline at end of file + delete(1, m) // ERROR "first argument to delete must be map|argument 1 must be a map|is not a map" +} diff --git a/test/method2.go b/test/method2.go index 790062c2af..2a92136d6c 100644 --- a/test/method2.go +++ b/test/method2.go @@ -33,9 +33,9 @@ var _ = (*Val).val // ERROR "method" var v Val var pv = &v -var _ = pv.val() // ERROR "pv.val undefined" -var _ = pv.val // ERROR "pv.val undefined" +var _ = pv.val() // ERROR "undefined|pointer to interface" +var _ = pv.val // ERROR "undefined|pointer to interface" func (t *T) g() int { return t.a } -var _ = (T).g() // ERROR "needs pointer receiver|undefined|cannot call pointer method" +var _ = (T).g() // ERROR "needs pointer receiver|undefined|method requires pointer|cannot call pointer method" diff --git a/test/run.go b/test/run.go index 3e0e7ab368..91bdd629bf 100644 --- a/test/run.go +++ b/test/run.go @@ -14,6 +14,7 @@ import ( "fmt" "hash/fnv" "io" + "io/fs" "io/ioutil" "log" "os" @@ -1869,7 +1870,7 @@ func overlayDir(dstRoot, srcRoot string) error { return err } - return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error { + return filepath.WalkDir(srcRoot, func(srcPath string, d fs.DirEntry, err error) error { if err != nil || srcPath == srcRoot { return err } @@ -1880,14 +1881,16 @@ func overlayDir(dstRoot, srcRoot string) error { } dstPath := filepath.Join(dstRoot, suffix) - perm := info.Mode() & os.ModePerm - if info.Mode()&os.ModeSymlink != 0 { + var info fs.FileInfo + if d.Type()&os.ModeSymlink != 0 { info, err = os.Stat(srcPath) - if err != nil { - return err - } - perm = info.Mode() & os.ModePerm + } else { + info, err = d.Info() } + if err != nil { + return err + } + perm := info.Mode() & os.ModePerm // Always copy directories (don't symlink them). // If we add a file in the overlay, we don't want to add it in the original. @@ -1933,6 +1936,7 @@ var excluded = map[string]bool{ "import5.go": true, // issue #42988 "import6.go": true, "initializerr.go": true, + "linkname2.go": true, "makechan.go": true, "makemap.go": true, "shift1.go": true, // issue #42989 diff --git a/test/shift1.go b/test/shift1.go index df0c032cd5..d6a6c38839 100644 --- a/test/shift1.go +++ b/test/shift1.go @@ -73,8 +73,8 @@ func _() { // 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" + _ = f2 << 2 // ERROR "shift of type float64|non-integer" + _ = s2 << 2 // ERROR "shift of type string|non-integer" } // shifts in comparisons w/ untyped operands diff --git a/test/syntax/chan1.go b/test/syntax/chan1.go index 56103d1d79..88a5b4777b 100644 --- a/test/syntax/chan1.go +++ b/test/syntax/chan1.go @@ -10,8 +10,8 @@ var c chan int var v int func main() { - if c <- v { // ERROR "cannot use c <- v as value" + if c <- v { // ERROR "cannot use c <- v as value|send statement used as value" } } -var _ = c <- v // ERROR "unexpected <-" +var _ = c <- v // ERROR "unexpected <-|send statement used as value" diff --git a/test/syntax/semi4.go b/test/syntax/semi4.go index f21431b3f5..08c354751b 100644 --- a/test/syntax/semi4.go +++ b/test/syntax/semi4.go @@ -8,5 +8,5 @@ package main func main() { for x // GCCGO_ERROR "undefined" - { // ERROR "unexpected {, expecting for loop condition" - z + { // ERROR "unexpected {, expecting for loop condition|expecting .*{.* after for clause" + z // GCCGO_ERROR "undefined" diff --git a/test/syntax/semi6.go b/test/syntax/semi6.go index 4a04f89ddb..9bc730d43d 100644 --- a/test/syntax/semi6.go +++ b/test/syntax/semi6.go @@ -6,6 +6,6 @@ package main -type T1 // ERROR "unexpected newline in type declaration" +type T1 // ERROR "newline in type declaration" -type T2 /* // ERROR "unexpected EOF in type declaration" */
\ No newline at end of file +type T2 /* // ERROR "(semicolon.*|EOF) in type declaration" */
\ No newline at end of file diff --git a/test/used.go b/test/used.go new file mode 100644 index 0000000000..a3f0e1270b --- /dev/null +++ b/test/used.go @@ -0,0 +1,144 @@ +// errorcheck + +// Copyright 2020 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 + +import "unsafe" + +const C = 1 + +var x, x1, x2 int +var b bool +var s string +var c chan int +var cp complex128 +var slice []int +var array [2]int +var bytes []byte +var runes []rune +var r rune + +func f0() {} +func f1() int { return 1 } +func f2() (int, int) { return 1, 1 } + +type T struct{ X int } + +func (T) M1() int { return 1 } +func (T) M0() {} +func (T) M() {} + +var t T +var tp *T + +type I interface{ M() } + +var i I + +var m map[int]int + +func _() { + // Note: if the next line changes to x, the error silences the x+x etc below! + x1 // ERROR "x1 .* not used" + + nil // ERROR "nil .* not used" + C // ERROR "C .* not used" + 1 // ERROR "1 .* not used" + x + x // ERROR "x \+ x .* not used" + x - x // ERROR "x - x .* not used" + x | x // ERROR "x \| x .* not used" + "a" + s // ERROR ".a. \+ s .* not used" + &x // ERROR "&x .* not used" + b && b // ERROR "b && b .* not used" + append(slice, 1) // ERROR "append\(slice, 1\) .* not used" + string(bytes) // ERROR "string\(bytes\) .* not used" + string(runes) // ERROR "string\(runes\) .* not used" + f0() // ok + f1() // ok + f2() // ok + _ = f0() // ERROR "f0\(\) .*used as value" + _ = f1() // ok + _, _ = f2() // ok + _ = f2() // ERROR "assignment mismatch: 1 variable but f2 returns 2 values|cannot assign" + T.M0 // ERROR "T.M0 .* not used" + t.M0 // ERROR "t.M0 .* not used" + cap // ERROR "use of builtin cap not in function call|must be called" + cap(slice) // ERROR "cap\(slice\) .* not used" + close(c) // ok + _ = close(c) // ERROR "close\(c\) .*used as value" + func() {} // ERROR "func literal .* not used|is not used" + X{} // ERROR "undefined: X" + map[string]int{} // ERROR "map\[string\]int{} .* not used" + struct{}{} // ERROR "struct ?{}{} .* not used" + [1]int{} // ERROR "\[1\]int{} .* not used" + []int{} // ERROR "\[\]int{} .* not used" + &struct{}{} // ERROR "&struct ?{}{} .* not used" + float32(x) // ERROR "float32\(x\) .* not used" + I(t) // ERROR "I\(t\) .* not used" + int(x) // ERROR "int\(x\) .* not used" + copy(slice, slice) // ok + _ = copy(slice, slice) // ok + delete(m, 1) // ok + _ = delete(m, 1) // ERROR "delete\(m, 1\) .*used as value" + t.X // ERROR "t.X .* not used" + tp.X // ERROR "tp.X .* not used" + t.M // ERROR "t.M .* not used" + I.M // ERROR "I.M .* not used" + i.(T) // ERROR "i.\(T\) .* not used" + x == x // ERROR "x == x .* not used" + x != x // ERROR "x != x .* not used" + x != x // ERROR "x != x .* not used" + x < x // ERROR "x < x .* not used" + x >= x // ERROR "x >= x .* not used" + x > x // ERROR "x > x .* not used" + *tp // ERROR "\*tp .* not used" + slice[0] // ERROR "slice\[0\] .* not used" + m[1] // ERROR "m\[1\] .* not used" + len(slice) // ERROR "len\(slice\) .* not used" + make(chan int) // ERROR "make\(chan int\) .* not used" + make(map[int]int) // ERROR "make\(map\[int\]int\) .* not used" + make([]int, 1) // ERROR "make\(\[\]int, 1\) .* not used" + x * x // ERROR "x \* x .* not used" + x / x // ERROR "x / x .* not used" + x % x // ERROR "x % x .* not used" + x << x // ERROR "x << x .* not used" + x >> x // ERROR "x >> x .* not used" + x & x // ERROR "x & x .* not used" + x &^ x // ERROR "x &\^ x .* not used" + new(int) // ERROR "new\(int\) .* not used" + !b // ERROR "!b .* not used" + ^x // ERROR "\^x .* not used" + +x // ERROR "\+x .* not used" + -x // ERROR "-x .* not used" + b || b // ERROR "b \|\| b .* not used" + panic(1) // ok + _ = panic(1) // ERROR "panic\(1\) .*used as value" + print(1) // ok + _ = print(1) // ERROR "print\(1\) .*used as value" + println(1) // ok + _ = println(1) // ERROR "println\(1\) .*used as value" + c <- 1 // ok + slice[1:1] // ERROR "slice\[1:1\] .* not used" + array[1:1] // ERROR "array\[1:1\] .* not used" + s[1:1] // ERROR "s\[1:1\] .* not used" + slice[1:1:1] // ERROR "slice\[1:1:1\] .* not used" + array[1:1:1] // ERROR "array\[1:1:1\] .* not used" + recover() // ok + <-c // ok + string(r) // ERROR "string\(r\) .* not used" + iota // ERROR "undefined: iota|cannot use iota" + real(cp) // ERROR "real\(cp\) .* not used" + imag(cp) // ERROR "imag\(cp\) .* not used" + complex(1, 2) // ERROR "complex\(1, 2\) .* not used" + unsafe.Alignof(t.X) // ERROR "unsafe.Alignof\(t.X\) .* not used" + unsafe.Offsetof(t.X) // ERROR "unsafe.Offsetof\(t.X\) .* not used" + unsafe.Sizeof(t) // ERROR "unsafe.Sizeof\(t\) .* not used" + _ = int // ERROR "type int is not an expression|not an expression" + (x) // ERROR "x .* not used|not used" + _ = new(x2) // ERROR "x2 is not a type|not a type" + // Disabled due to issue #43125. + // _ = new(1 + 1) // DISABLED "1 \+ 1 is not a type" +} diff --git a/test/winbatch.go b/test/winbatch.go index c3b48d385c..54c2fff134 100644 --- a/test/winbatch.go +++ b/test/winbatch.go @@ -27,11 +27,11 @@ func main() { // Walk the entire Go repository source tree (without GOROOT/pkg), // skipping directories that start with "." and named "testdata", // and ensure all .bat files found have exact CRLF line endings. - err := filepath.Walk(runtime.GOROOT(), func(path string, fi os.FileInfo, err error) error { + err := filepath.WalkDir(runtime.GOROOT(), func(path string, d os.DirEntry, err error) error { if err != nil { return err } - if fi.IsDir() && (strings.HasPrefix(fi.Name(), ".") || fi.Name() == "testdata") { + if d.IsDir() && (strings.HasPrefix(d.Name(), ".") || d.Name() == "testdata") { return filepath.SkipDir } if path == filepath.Join(runtime.GOROOT(), "pkg") { @@ -39,7 +39,7 @@ func main() { // Skip it to avoid false positives. (Also see golang.org/issue/37929.) return filepath.SkipDir } - if filepath.Ext(fi.Name()) == ".bat" { + if filepath.Ext(d.Name()) == ".bat" { enforceBatchStrictCRLF(path) } return nil |
