Skip to content

Commit c8f1436

Browse files
odeke-emrandall77
authored andcommitted
test: lock in test for _ assignment evaluation/zerodivide panic
Fixes #5790. Fixes #18421. * Lock in _ = x1/x2 divide by zero runtime panics since it is actually evaluated and not discarded as in previous versions before Go1.8. * Update a test that was skipping over zerodivide tests that expected runtime panics, enabling us to check for the expected panics. Change-Id: I0af0a6ecc19345fa9763ab2e35b275fb2d9d0194 Reviewed-on: https://go-review.googlesource.com/34712 Reviewed-by: Keith Randall <[email protected]>
1 parent db07c9e commit c8f1436

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/zerodivide.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var (
2828
i32, j32, k32 int32 = 0, 0, 1
2929
i64, j64, k64 int64 = 0, 0, 1
3030

31+
bb = []int16{2, 0}
32+
3133
u, v, w uint = 0, 0, 1
3234
u8, v8, w8 uint8 = 0, 0, 1
3335
u16, v16, w16 uint16 = 0, 0, 1
@@ -124,6 +126,10 @@ var errorTests = []ErrorTest{
124126
ErrorTest{"int32 1/0", func() { use(k32 / j32) }, "divide"},
125127
ErrorTest{"int64 1/0", func() { use(k64 / j64) }, "divide"},
126128

129+
// From issue 5790, we should ensure that _ assignments
130+
// still evaluate and generate zerodivide panics.
131+
ErrorTest{"int16 _ = bb[0]/bb[1]", func() { _ = bb[0] / bb[1] }, "divide"},
132+
127133
ErrorTest{"uint 0/0", func() { use(u / v) }, "divide"},
128134
ErrorTest{"uint8 0/0", func() { use(u8 / v8) }, "divide"},
129135
ErrorTest{"uint16 0/0", func() { use(u16 / v16) }, "divide"},
@@ -195,9 +201,6 @@ func alike(a, b float64) bool {
195201
func main() {
196202
bad := false
197203
for _, t := range errorTests {
198-
if t.err != "" {
199-
continue
200-
}
201204
err := error_(t.fn)
202205
switch {
203206
case t.err == "" && err == "":

0 commit comments

Comments
 (0)