Skip to content

Commit 72ad2f4

Browse files
committed
[dev.typeparams] test: add scaffolding to run.go to check compiler with -G flag
Added a new flag -G to run. Setting -G (as in: go run run.go -G) will run tests marked with "errorcheck" (and no other flags) also with the compiler using the new typechecker. Many tests don't pass yet (due to discrepancies in error messages). The top-level tests in the test directory which don't pass yet have been explicitly excluded, permitting to see the current status. Future CLs will bring error messages in sync and eventually all tests should pass. Change-Id: I7caf5eff413e173f68d092af4bbe458434718d74 Reviewed-on: https://go-review.googlesource.com/c/go/+/274313 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 87bc85a commit 72ad2f4

File tree

11 files changed

+208
-97
lines changed

11 files changed

+208
-97
lines changed

src/cmd/compile/internal/gc/noder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ func parseFiles(filenames []string, allowGenerics bool) (lines uint) {
8383
}
8484

8585
conf := types2.Config{
86-
InferFromConstraints: true,
86+
InferFromConstraints: true,
87+
CompilerErrorMessages: true,
8788
Error: func(err error) {
8889
terr := err.(types2.Error)
8990
if len(terr.Msg) > 0 && terr.Msg[0] == '\t' {

test/alias2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type (
3636

3737
// Methods can be declared on the original named type and the alias.
3838
func (T0) m1() {} // GCCGO_ERROR "previous"
39-
func (*T0) m1() {} // ERROR "method redeclared: T0\.m1|redefinition of .m1."
39+
func (*T0) m1() {} // ERROR "method redeclared: T0\.m1|T0\.m1 redeclared in this block|redefinition of .m1."
4040
func (A0) m1() {} // ERROR "T0\.m1 redeclared in this block|redefinition of .m1."
4141
func (A0) m1() {} // ERROR "T0\.m1 redeclared in this block|redefinition of .m1."
4242
func (A0) m2() {}
@@ -90,7 +90,7 @@ func _() {
9090

9191
// Invalid type alias declarations.
9292

93-
type _ = reflect.ValueOf // ERROR "reflect.ValueOf is not a type|expected type"
93+
type _ = reflect.ValueOf // ERROR "reflect.ValueOf .*is not a type|expected type"
9494

9595
func (A1) m() {} // ERROR "cannot define new methods on non-local type int|may not define methods on non-local type"
9696
func (A2) m() {} // ERROR "invalid receiver type"

test/append1.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ func main() {
1313

1414
s := make([]int, 8)
1515

16-
_ = append() // ERROR "missing arguments to append"
17-
_ = append(s...) // ERROR "cannot use ... on first argument"
18-
_ = append(s, 2, s...) // ERROR "too many arguments to append"
16+
_ = append() // ERROR "missing arguments to append|not enough arguments for append"
17+
_ = append(s...) // ERROR "cannot use ... on first argument|not enough arguments in call to append"
18+
_ = append(s, 2, s...) // ERROR "too many arguments to append|too many arguments in call to append"
1919

20-
_ = append(s, make([]int, 0)) // ERROR "cannot use make.* as type int in append"
21-
_ = append(s, make([]int, -1)...) // ERROR "negative len argument in make"
20+
_ = append(s, make([]int, 0)) // ERROR "cannot use make.* as type int in append|cannot use make.* as int value"
21+
_ = append(s, make([]int, -1)...) // ERROR "negative len argument in make|index -1.* must not be negative"
2222
}

test/assign.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
_ = x
4343
}
4444
{
45-
x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
45+
x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex|unknown field.* in struct literal"
4646
_ = x
4747
}
4848
{
@@ -56,13 +56,13 @@ func main() {
5656
{
5757
var x = 1
5858
{
59-
x, x := 2, 3 // ERROR "x repeated on left side of :="
59+
x, x := 2, 3 // ERROR "x repeated on left side of :=|x redeclared in this block"
6060
_ = x
6161
}
6262
_ = x
6363
}
6464
{
65-
a, a := 1, 2 // ERROR "a repeated on left side of :="
65+
a, a := 1, 2 // ERROR "a repeated on left side of :=|a redeclared in this block"
6666
_ = a
6767
}
6868
}

test/blank1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func main() {
2525
_() // ERROR "cannot use .* as value"
2626
x := _+1 // ERROR "cannot use .* as value"
2727
_ = x
28-
_ = t._ // ERROR "cannot refer to blank field|invalid use of"
28+
_ = t._ // ERROR "cannot refer to blank field|invalid use of|t._ undefined"
2929

3030
var v1, v2 T
31-
_ = v1 == v2 // ERROR "cannot be compared|non-comparable"
31+
_ = v1 == v2 // ERROR "cannot be compared|non-comparable|cannot compare v1 == v2"
3232
}

test/cannotassign.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ package main
1010

1111
func main() {
1212
var s string = "hello"
13-
s[1:2] = "a" // ERROR "cannot assign to .* \(strings are immutable\)"
14-
s[3] = "b" // ERROR "cannot assign to .* \(strings are immutable\)"
13+
s[1:2] = "a" // ERROR "cannot assign to .* (\(strings are immutable\))?"
14+
s[3] = "b" // ERROR "cannot assign to .* (\(strings are immutable\))?"
1515

1616
const n int = 1
1717
const cs string = "hello"
18-
n = 2 // ERROR "cannot assign to .* \(declared const\)"
19-
cs = "hi" // ERROR "cannot assign to .* \(declared const\)"
20-
true = false // ERROR "cannot assign to .* \(declared const\)"
18+
n = 2 // ERROR "cannot assign to .* (\(declared const\))?"
19+
cs = "hi" // ERROR "cannot assign to .* (\(declared const\))?"
20+
true = false // ERROR "cannot assign to .* (\(declared const\))?"
2121

2222
var m map[int]struct{ n int }
2323
m[0].n = 7 // ERROR "cannot assign to struct field .* in map$"
2424

25-
1 = 7 // ERROR "cannot assign to 1$"
26-
"hi" = 7 // ERROR `cannot assign to "hi"$`
27-
nil = 7 // ERROR "cannot assign to nil$"
28-
len("") = 7 // ERROR `cannot assign to len\(""\)$`
29-
[]int{} = nil // ERROR "cannot assign to \[\]int\{\}$"
25+
1 = 7 // ERROR "cannot assign to 1"
26+
"hi" = 7 // ERROR `cannot assign to "hi"`
27+
nil = 7 // ERROR "cannot assign to nil"
28+
len("") = 7 // ERROR `cannot assign to len\(""\)`
29+
[]int{} = nil // ERROR "cannot assign to \[\]int\{\}"
3030

3131
var x int = 7
32-
x + 1 = 7 // ERROR "cannot assign to x \+ 1$"
32+
x + 1 = 7 // ERROR "cannot assign to x \+ 1"
3333
}

test/cmp6.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ func main() {
6363
use(a3 == a3) // ERROR "invalid operation|invalid comparison"
6464

6565
// Comparison of structs should have a good message
66-
use(t3 == t3) // ERROR "struct|expected"
67-
use(t4 == t4) // ERROR "cannot be compared|non-comparable"
66+
use(t3 == t3) // ERROR "struct|expected|cannot compare"
67+
use(t4 == t4) // ERROR "cannot be compared|non-comparable|cannot compare"
6868

6969
// Slices, functions, and maps too.
7070
var x []int
7171
var f func()
7272
var m map[int]int
73-
use(x == x) // ERROR "slice can only be compared to nil"
74-
use(f == f) // ERROR "func can only be compared to nil"
75-
use(m == m) // ERROR "map can only be compared to nil"
73+
use(x == x) // ERROR "slice can only be compared to nil|cannot compare"
74+
use(f == f) // ERROR "func can only be compared to nil|cannot compare"
75+
use(m == m) // ERROR "map can only be compared to nil|cannot compare"
7676

7777
// Comparison with interface that cannot return true
7878
// (would panic).

test/const1.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,43 @@ const (
3030
)
3131

3232
var (
33-
a1 = Int8 * 100 // ERROR "overflow"
33+
a1 = Int8 * 100 // ERROR "overflow|cannot convert"
3434
a2 = Int8 * -1 // OK
35-
a3 = Int8 * 1000 // ERROR "overflow"
36-
a4 = Int8 * int8(1000) // ERROR "overflow"
37-
a5 = int8(Int8 * 1000) // ERROR "overflow"
38-
a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
39-
a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
40-
a8 = Int8 * Const / 100 // ERROR "overflow"
35+
a3 = Int8 * 1000 // ERROR "overflow|cannot convert"
36+
a4 = Int8 * int8(1000) // ERROR "overflow|cannot convert"
37+
a5 = int8(Int8 * 1000) // ERROR "overflow|cannot convert"
38+
a6 = int8(Int8 * int8(1000)) // ERROR "overflow|cannot convert"
39+
a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow|cannot convert"
40+
a8 = Int8 * Const / 100 // ERROR "overflow|cannot convert"
4141
a9 = Int8 * (Const / 100) // OK
4242

43-
b1 = Uint8 * Uint8 // ERROR "overflow"
44-
b2 = Uint8 * -1 // ERROR "overflow"
43+
b1 = Uint8 * Uint8 // ERROR "overflow|cannot convert"
44+
b2 = Uint8 * -1 // ERROR "overflow|cannot convert"
4545
b3 = Uint8 - Uint8 // OK
46-
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
47-
b5 = uint8(^0) // ERROR "overflow"
46+
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow|cannot convert"
47+
b5 = uint8(^0) // ERROR "overflow|cannot convert"
4848
b5a = int64(^0) // OK
4949
b6 = ^uint8(0) // OK
5050
b6a = ^int64(0) // OK
51-
b7 = uint8(Minus1) // ERROR "overflow"
52-
b8 = uint8(int8(-1)) // ERROR "overflow"
53-
b8a = uint8(-1) // ERROR "overflow"
51+
b7 = uint8(Minus1) // ERROR "overflow|cannot convert"
52+
b8 = uint8(int8(-1)) // ERROR "overflow|cannot convert"
53+
b8a = uint8(-1) // ERROR "overflow|cannot convert"
5454
b9 byte = (1 << 10) >> 8 // OK
55-
b10 byte = (1 << 10) // ERROR "overflow"
56-
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
57-
b12 byte = 1000 // ERROR "overflow"
58-
b13 byte = byte(1000) // ERROR "overflow"
59-
b14 byte = byte(100) * byte(100) // ERROR "overflow"
60-
b15 byte = byte(100) * 100 // ERROR "overflow"
61-
b16 byte = byte(0) * 1000 // ERROR "overflow"
55+
b10 byte = (1 << 10) // ERROR "overflow|cannot convert"
56+
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow|cannot convert"
57+
b12 byte = 1000 // ERROR "overflow|cannot convert"
58+
b13 byte = byte(1000) // ERROR "overflow|cannot convert"
59+
b14 byte = byte(100) * byte(100) // ERROR "overflow|cannot convert"
60+
b15 byte = byte(100) * 100 // ERROR "overflow|cannot convert"
61+
b16 byte = byte(0) * 1000 // ERROR "overflow|cannot convert"
6262
b16a byte = 0 * 1000 // OK
63-
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
63+
b17 byte = byte(0) * byte(1000) // ERROR "overflow|cannot convert"
6464
b18 byte = Uint8 / 0 // ERROR "division by zero"
6565

6666
c1 float64 = Big
67-
c2 float64 = Big * Big // ERROR "overflow"
68-
c3 float64 = float64(Big) * Big // ERROR "overflow"
69-
c4 = Big * Big // ERROR "overflow"
67+
c2 float64 = Big * Big // ERROR "overflow|cannot convert"
68+
c3 float64 = float64(Big) * Big // ERROR "overflow|cannot convert"
69+
c4 = Big * Big // ERROR "overflow|cannot convert"
7070
c5 = Big / 0 // ERROR "division by zero"
7171
c6 = 1000 % 1e3 // ERROR "invalid operation|expected integer type"
7272
)
@@ -87,8 +87,8 @@ func main() {
8787
f(Bool) // ERROR "convert|wrong type|cannot|incompatible"
8888
}
8989

90-
const ptr = nil // ERROR "const.*nil"
90+
const ptr = nil // ERROR "const.*nil|not constant"
9191
const _ = string([]byte(nil)) // ERROR "is not a? ?constant"
9292
const _ = uintptr(unsafe.Pointer((*int)(nil))) // ERROR "is not a? ?constant"
93-
const _ = unsafe.Pointer((*int)(nil)) // ERROR "cannot be nil|invalid constant type|is not a constant"
94-
const _ = (*int)(nil) // ERROR "cannot be nil|invalid constant type|is not a constant"
93+
const _ = unsafe.Pointer((*int)(nil)) // ERROR "cannot be nil|invalid constant type|is not a constant|not constant"
94+
const _ = (*int)(nil) // ERROR "cannot be nil|invalid constant type|is not a constant|not constant"

test/const2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package main
1111

1212
const (
1313
A int = 1
14-
B byte; // ERROR "type without expr|expected .=."
14+
B byte; // ERROR "type without expr|expected .=.|missing init expr"
1515
)
1616

1717
const LargeA = 1000000000000000000
@@ -23,7 +23,7 @@ const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shif
2323
// Issue #42732.
2424

2525
const a = 1e+500000000
26-
const b = a * a // ERROR "constant multiplication overflow"
26+
const b = a * a // ERROR "constant multiplication overflow|not representable"
2727
const c = b * b
2828

2929
const MaxInt512 = (1<<256 - 1) * (1<<256 + 1)

0 commit comments

Comments
 (0)