Skip to content

Commit

Permalink
go/types, types2: consolidate testdata/check test files
Browse files Browse the repository at this point in the history
Use the go/types version of testdata/check tests where the diffs
are only in the error positions (the types2 test harness allows
for some position tolerance). Consolidate files where there are
other minor differences.

Comment out a couple of tests that are different between the two
type checkers.

With this CL, the testdata/check files are identical between the
two type checkers.

For #54511.

Change-Id: Ibdff2ca3ec9bdaca3aa84029a7883bb83d2d2060
Reviewed-on: https://go-review.googlesource.com/c/go/+/425735
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
griesemer authored and Robert Griesemer committed Sep 1, 2022
1 parent aa5ff29 commit bbaf0a5
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 118 deletions.
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/types2/testdata/check/builtins0.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func append1() {
_ = append(s, b)
_ = append(s, x /* ERROR cannot use x */ )
_ = append(s, s /* ERROR cannot use s */ )
_ = append(s /* ERROR not enough arguments */ ...)
_ = append(s, b, s /* ERROR too many arguments */ ... )
_ = append(s...) /* ERROR not enough arguments */
_ = append(s, b, s /* ERROR too many arguments */ ...)
_ = append(s, 1, 2, 3)
_ = append(s, 1, 2, 3, x /* ERROR cannot use x */ , 5, 6, 6)
_ = append(s, 1, 2 /* ERROR too many arguments */ , s... )
_ = append(s, 1, 2 /* ERROR too many arguments */, s...)
_ = append([]interface{}(nil), 1, 2, "foo", x, 3.1425, false)

type S []byte
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/builtins1.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func _[T ~[]byte](x, y T) {
type myByte byte
var x3 []myByte
copy(x3 /* ERROR different element types */ , y)
copy(y, x3 /* ERROR different element types */ )
copy(y /* ERROR different element types */ , x3)
}

func _[T ~[]E, E any](x T, y []E) {
Expand Down Expand Up @@ -144,7 +144,7 @@ func _[
_ = make([]int, 10)
_ = make(S0, 10)
_ = make(S1, 10)
_ = make /* ERROR not enough arguments */ ()
_ = make() /* ERROR not enough arguments */
_ = make /* ERROR expects 2 or 3 arguments */ (S1)
_ = make(S1, 10, 20)
_ = make /* ERROR expects 2 or 3 arguments */ (S1, 10, 20, 30)
Expand Down
10 changes: 6 additions & 4 deletions src/cmd/compile/internal/types2/testdata/check/decls0.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ func f1(x f1 /* ERROR "not a type" */ ) {}
func f2(x *f2 /* ERROR "not a type" */ ) {}
func f3() (x f3 /* ERROR "not a type" */ ) { return }
func f4() (x *f4 /* ERROR "not a type" */ ) { return }
// TODO(#43215) this should be detected as a cycle error
func f5([unsafe.Sizeof(f5)]int) {}

func (S0) m1(x S0 /* ERROR illegal cycle in method declaration */ .m1) {}
func (S0) m2(x *S0 /* ERROR illegal cycle in method declaration */ .m2) {}
func (S0) m3() (x S0 /* ERROR illegal cycle in method declaration */ .m3) { return }
func (S0) m4() (x *S0 /* ERROR illegal cycle in method declaration */ .m4) { return }
func (S0) m1 (x S0 /* ERROR illegal cycle in method declaration */ .m1) {}
func (S0) m2 (x *S0 /* ERROR illegal cycle in method declaration */ .m2) {}
func (S0) m3 () (x S0 /* ERROR illegal cycle in method declaration */ .m3) { return }
func (S0) m4 () (x *S0 /* ERROR illegal cycle in method declaration */ .m4) { return }

// interfaces may not have any blank methods
type BlankI interface {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/compile/internal/types2/testdata/check/decls1.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ var (
v11 = xx/yy*yy - xx
v12 = true && false
v13 = nil /* ERROR "use of untyped nil" */
v14 string = 257 // ERROR cannot use 257 .* as string value in variable declaration$
v15 int8 = 257 // ERROR cannot use 257 .* as int8 value in variable declaration .*overflows
)

// Multiple assignment expressions
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/compile/internal/types2/testdata/check/decls2/decls2a.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func (ptr /* ERROR "invalid receiver" */ ) _() {}
func (* /* ERROR "invalid receiver" */ ptr) _() {}

// Methods with zero or multiple receivers.
func ( /* ERROR "no receiver" */ ) _() {}
func (T3, * /* ERROR "multiple receivers" */ T3) _() {}
func (T3, T3, T3 /* ERROR "multiple receivers" */ ) _() {}
func (a, b /* ERROR "multiple receivers" */ T3) _() {}
func (a, b, c /* ERROR "multiple receivers" */ T3) _() {}
func ( /* ERROR "method has no receiver" */ ) _() {}
func (T3, * /* ERROR "method has multiple receivers" */ T3) _() {}
func (T3, T3, T3 /* ERROR "method has multiple receivers" */ ) _() {}
func (a, b /* ERROR "method has multiple receivers" */ T3) _() {}
func (a, b, c /* ERROR "method has multiple receivers" */ T3) _() {}

// Methods associated with non-local or unnamed types.
func (int /* ERROR "cannot define new methods on non-local type int" */ ) m() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ var (
_ = (*T7).m4
_ = (*T7).m5
_ = (*T7).m6
)
)
10 changes: 5 additions & 5 deletions src/cmd/compile/internal/types2/testdata/check/decls3.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ func _() {
_ = S2{}.B
_ = S2{}.C
_ = S2{}.D /* ERROR "no field or method" */
_ = S3{}.S1 /* ERROR "ambiguous selector S3\{\}.S1" */
_ = S3{}.S1 /* ERROR "ambiguous selector S3{}.S1" */
_ = S3{}.A
_ = S3{}.B /* ERROR "ambiguous selector" S3\{\}.B */
_ = S3{}.B /* ERROR "ambiguous selector" S3{}.B */
_ = S3{}.D
_ = S3{}.E
_ = S4{}.A
_ = S4{}.B /* ERROR "no field or method" */
_ = S5{}.X /* ERROR "ambiguous selector S5\{\}.X" */
_ = S5{}.X /* ERROR "ambiguous selector S5{}.X" */
_ = S5{}.Y
_ = S10{}.X /* ERROR "ambiguous selector S10\{\}.X" */
_ = S10{}.X /* ERROR "ambiguous selector S10{}.X" */
_ = S10{}.Y
}

Expand Down Expand Up @@ -306,4 +306,4 @@ type R22 R21
type R23 R21
type R24 R21

var _ = R0{}.X /* ERROR "ambiguous selector R0\{\}.X" */
var _ = R0{}.X /* ERROR "ambiguous selector R0{}.X" */
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/decls4.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ type eD struct {
}

var (
_ = eD{}.xf /* ERROR ambiguous selector eD\{\}.xf */
_ = eD{}.xm /* ERROR ambiguous selector eD\{\}.xm */
_ = eD{}.xf /* ERROR ambiguous selector eD{}.xf */
_ = eD{}.xm /* ERROR ambiguous selector eD{}.xm */
)

var (
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/testdata/check/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func f(x int, m map[string]int) {

// values
nil // ERROR nil is not used
(*int)(nil) // ERROR \(\*int\)\(nil\) \(value of type \*int\) is not used
( /* ERROR \(\*int\)\(nil\) \(value of type \*int\) is not used */ *int)(nil)
x /* ERROR x != x \(untyped bool value\) is not used */ != x
x /* ERROR x \+ x \(value of type int\) is not used */ + x

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/testdata/check/expr0.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ var (
_ = ~ /* ERROR cannot use ~ outside of interface or type constraint */ 0
_ = ~ /* ERROR cannot use ~ outside of interface or type constraint */ "foo"
_ = ~ /* ERROR cannot use ~ outside of interface or type constraint */ i0
)
)
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/expr1.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ type mystring string
func _(x, y string, z mystring) {
x = x + "foo"
x = x /* ERROR not defined */ - "foo"
x = x + 1 // ERROR mismatched types string and untyped int
x = x /* ERROR mismatched types string and untyped int */ + 1
x = x + y
x = x /* ERROR not defined */ - y
x = x * 10 // ERROR mismatched types string and untyped int
x = x /* ERROR mismatched types string and untyped int */* 10
}

func f() (a, b int) { return }
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/expr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func arrays() {
_ = a == b
_ = a != b
_ = a /* ERROR < not defined */ < b
_ = a == nil /* ERROR invalid operation.*mismatched types */
_ = a /* ERROR cannot compare.*mismatched types */ == nil

type C [10]int
var c C
Expand All @@ -53,7 +53,7 @@ func structs() {
_ = s == t
_ = s != t
_ = s /* ERROR < not defined */ < t
_ = s == nil /* ERROR invalid operation.*mismatched types */
_ = s /* ERROR cannot compare.*mismatched types */ == nil

type S struct {
x int
Expand Down
27 changes: 13 additions & 14 deletions src/cmd/compile/internal/types2/testdata/check/expr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ package expr3
import "time"

func indexes() {
var x int
_ = 1 /* ERROR "cannot index" */ [0]
_ = x /* ERROR "cannot index" */ [0]
_ = indexes /* ERROR "cannot index" */ [0]
_ = ( /* ERROR "cannot slice" */ 12 + 3)[1:2]

var a [10]int
Expand Down Expand Up @@ -83,7 +82,7 @@ func indexes() {
_ = s[: - /* ERROR "negative" */ 1]
_ = s[0]
_ = s[1:2]
_ = s[2:1] /* ERROR "invalid slice indices" */
_ = s[2:1 /* ERROR "invalid slice indices" */ ]
_ = s[2:]
_ = s[: 1 /* ERROR "overflows" */ <<100]
_ = s[1 /* ERROR "overflows" */ <<100 :]
Expand All @@ -104,7 +103,7 @@ func indexes() {
var ok mybool
_, ok = m["bar"]
_ = ok
_ = m[0 /* ERROR "cannot use 0" */ ] + "foo" // ERROR "mismatched types int and untyped string"
_ = m/* ERROR "mismatched types int and untyped string" */[0 /* ERROR "cannot use 0" */ ] + "foo"

var t string
_ = t[- /* ERROR "negative" */ 1]
Expand Down Expand Up @@ -459,7 +458,7 @@ func type_asserts() {

var t I
_ = t /* ERROR "use of .* outside type switch" */ .(type)
_ = t /* ERROR "method m has pointer receiver" */ .(T)
_ = t /* ERROR "m has pointer receiver" */ .(T)
_ = t.(*T)
_ = t /* ERROR "missing method m" */ .(T1)
_ = t /* ERROR "wrong type for method m" */ .(T2)
Expand Down Expand Up @@ -494,23 +493,23 @@ func _calls() {
f1(0)
f1(x)
f1(10.0)
f1 /* ERROR "not enough arguments in call to f1\n\thave \(\)\n\twant \(int\)" */ ()
f1() /* ERROR "not enough arguments in call to f1\n\thave \(\)\n\twant \(int\)" */
f1(x, y /* ERROR "too many arguments in call to f1\n\thave \(int, float32\)\n\twant \(int\)" */ )
f1(s /* ERROR "cannot use .* in argument" */ )
f1(x ... /* ERROR "cannot use ..." */ )
f1(g0 /* ERROR "used as value" */ ())
f1(g1())
f1(g2 /* ERROR "too many arguments in call to f1\n\thave \(float32, string\)\n\twant \(int\)" */ ())

f2 /* ERROR "not enough arguments in call to f2\n\thave \(\)\n\twant \(float32, string\)" */ ()
f2(3.14 /* ERROR "not enough arguments in call to f2\n\thave \(number\)\n\twant \(float32, string\)" */ )
f2() /* ERROR "not enough arguments in call to f2\n\thave \(\)\n\twant \(float32, string\)" */
f2(3.14) /* ERROR "not enough arguments in call to f2\n\thave \(number\)\n\twant \(float32, string\)" */
f2(3.14, "foo")
f2(x /* ERROR "cannot use .* in argument" */ , "foo")
f2(g0 /* ERROR "used as value" */ ())
f2(g1 /* ERROR "not enough arguments in call to f2\n\thave \(int\)\n\twant \(float32, string\)" */ ())
f2(g1()) /* ERROR "not enough arguments in call to f2\n\thave \(int\)\n\twant \(float32, string\)" */
f2(g2())

fs /* ERROR "not enough arguments" */ ()
fs() /* ERROR "not enough arguments" */
fs(g0 /* ERROR "used as value" */ ())
fs(g1 /* ERROR "cannot use .* in argument" */ ())
fs(g2 /* ERROR "too many arguments" */ ())
Expand All @@ -521,7 +520,7 @@ func _calls() {
fv(s /* ERROR "cannot use .* in argument" */ )
fv(s...)
fv(x /* ERROR "cannot use" */ ...)
fv(1, s /* ERROR "too many arguments" */ ... )
fv(1, s /* ERROR "too many arguments" */ ...)
fv(gs /* ERROR "cannot use .* in argument" */ ())
fv(gs /* ERROR "cannot use .* in argument" */ ()...)

Expand All @@ -530,15 +529,15 @@ func _calls() {
t.fm(1, 2.0, x)
t.fm(s /* ERROR "cannot use .* in argument" */ )
t.fm(g1())
t.fm(1, s /* ERROR "too many arguments" */ ... )
t.fm(1, s /* ERROR "too many arguments" */ ...)
t.fm(gs /* ERROR "cannot use .* in argument" */ ())
t.fm(gs /* ERROR "cannot use .* in argument" */ ()...)

T.fm(t, )
T.fm(t, 1, 2.0, x)
T.fm(t, s /* ERROR "cannot use .* in argument" */ )
T.fm(t, g1())
T.fm(t, 1, s /* ERROR "too many arguments" */ ... )
T.fm(t, 1, s /* ERROR "too many arguments" */ ...)
T.fm(t, gs /* ERROR "cannot use .* in argument" */ ())
T.fm(t, gs /* ERROR "cannot use .* in argument" */ ()...)

Expand All @@ -547,7 +546,7 @@ func _calls() {
i.fm(1, 2.0, x)
i.fm(s /* ERROR "cannot use .* in argument" */ )
i.fm(g1())
i.fm(1, s /* ERROR "too many arguments" */ ... )
i.fm(1, s /* ERROR "too many arguments" */ ...)
i.fm(gs /* ERROR "cannot use .* in argument" */ ())
i.fm(gs /* ERROR "cannot use .* in argument" */ ()...)

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/testdata/check/go1_8.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
package p

// type alias declarations
type any /* ERROR type aliases requires go1.9 or later */ = interface{}
type any = /* ERROR type aliases requires go1.9 or later */ interface{}
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/issues0.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func issue28281c(a, b, c ... /* ERROR can only use ... with final parameter */ i
func issue28281d(... /* ERROR can only use ... with final parameter */ int, int)
func issue28281e(a, b, c ... /* ERROR can only use ... with final parameter */ int, d int)
func issue28281f(... /* ERROR can only use ... with final parameter */ int, ... /* ERROR can only use ... with final parameter */ int, int)
func (... /* ERROR can only use ... with final parameter in list */ TT) f()
func issue28281g() (... /* ERROR can only use ... with final parameter in list */ TT)
func (... /* ERROR can only use ... with final parameter */ TT) f()
func issue28281g() (... /* ERROR can only use ... with final parameter */ TT)

// Issue #26234: Make various field/method lookup errors easier to read by matching cmd/compile's output
func issue26234a(f *syn.Prog) {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/main1.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Copyright 2021 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

func main [T /* ERROR "func main must have no type parameters" */ any]() {}
func main[T /* ERROR "func main must have no type parameters" */ any]() {}
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/testdata/check/map1.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ type chans_Receiver[T any] struct {
func (r *chans_Receiver[T]) Next() (T, bool) {
v, ok := <-r.values
return v, ok
}
}
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/types2/testdata/check/shifts.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ func shifts6() {
_ = float32(1.0 /* ERROR "must be integer" */ <<s)
_ = float32(1.1 /* ERROR "must be integer" */ <<s)

// TODO(gri) port fixes from go/types
// TODO(gri) Re-enable these tests once types2 has the go/types fixes.
// Issue #52080.
// _ = int32(0x80000000 /* ERROR "overflows int32" */ << s)
// TODO(rfindley) Eliminate the redundant error here.
// _ = int32(( /* ERROR "truncated to int32" */ 0x80000000 /* ERROR "truncated to int32" */ + 0i) << s)
Expand Down
Loading

0 comments on commit bbaf0a5

Please sign in to comment.