GoPLS Viewer

Home|gopls/go/ssa/interp/testdata/convert.go
1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Test conversion operations.
6
7package main
8
9func left(x int)  { _ = 1 << x }
10func right(x int) { _ = 1 >> x }
11
12func main() {
13    wantPanic(
14        func() {
15            left(-1)
16        },
17        "runtime error: negative shift amount",
18    )
19    wantPanic(
20        func() {
21            right(-1)
22        },
23        "runtime error: negative shift amount",
24    )
25    wantPanic(
26        func() {
27            const maxInt32 = 1<<31 - 1
28            var idx int64 = maxInt32*2 + 8
29            x := make([]int16)
30            _ = x[idx]
31        },
32        "runtime error: runtime error: index out of range [4294967302] with length 16",
33    )
34}
35
36func wantPanic(fn func(), s string) {
37    defer func() {
38        err := recover()
39        if err == nil {
40            panic("expected panic")
41        }
42        if got := err.(error).Error(); got != s {
43            panic("expected panic " + s + " got " + got)
44        }
45    }()
46    fn()
47}
48
MembersX
right.x
wantPanic
wantPanic.BlockStmt.err
left
left.x
main.BlockStmt.BlockStmt.x
wantPanic.fn
wantPanic.s
wantPanic.BlockStmt.got
right
main.BlockStmt.BlockStmt.idx
Members
X