Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- platform/dbops/binaries/go/go/test/blank.go +189 -0
- platform/dbops/binaries/go/go/test/blank1.go +32 -0
- platform/dbops/binaries/go/go/test/bom.go +26 -0
- platform/dbops/binaries/go/go/test/bombad.go +18 -0
- platform/dbops/binaries/go/go/test/bounds.go +284 -0
- platform/dbops/binaries/go/go/test/cannotassign.go +33 -0
- platform/dbops/binaries/go/go/test/chancap.go +71 -0
- platform/dbops/binaries/go/go/test/chanlinear.go +95 -0
- platform/dbops/binaries/go/go/test/char_lit.go +45 -0
- platform/dbops/binaries/go/go/test/char_lit1.go +28 -0
- platform/dbops/binaries/go/go/test/checkbce.go +186 -0
- platform/dbops/binaries/go/go/test/clear.go +47 -0
- platform/dbops/binaries/go/go/test/clearfat.go +68 -0
- platform/dbops/binaries/go/go/test/closedchan.go +359 -0
- platform/dbops/binaries/go/go/test/closure.go +128 -0
- platform/dbops/binaries/go/go/test/closure1.go +19 -0
- platform/dbops/binaries/go/go/test/closure2.go +133 -0
- platform/dbops/binaries/go/go/test/closure3.go +12 -0
- platform/dbops/binaries/go/go/test/closure4.go +21 -0
- platform/dbops/binaries/go/go/test/closure5.go +10 -0
- platform/dbops/binaries/go/go/test/closure6.go +18 -0
- platform/dbops/binaries/go/go/test/closure7.go +28 -0
- platform/dbops/binaries/go/go/test/cmp.go +488 -0
- platform/dbops/binaries/go/go/test/cmp6.go +86 -0
- platform/dbops/binaries/go/go/test/cmplx.go +68 -0
- platform/dbops/binaries/go/go/test/cmplxdivide.c +98 -0
- platform/dbops/binaries/go/go/test/cmplxdivide.go +44 -0
- platform/dbops/binaries/go/go/test/cmplxdivide1.go +0 -0
- platform/dbops/binaries/go/go/test/complit.go +120 -0
- platform/dbops/binaries/go/go/test/complit1.go +65 -0
- platform/dbops/binaries/go/go/test/compos.go +25 -0
- platform/dbops/binaries/go/go/test/const.go +210 -0
- platform/dbops/binaries/go/go/test/const1.go +94 -0
- platform/dbops/binaries/go/go/test/const2.go +32 -0
- platform/dbops/binaries/go/go/test/const3.go +37 -0
- platform/dbops/binaries/go/go/test/const4.go +82 -0
- platform/dbops/binaries/go/go/test/const5.go +37 -0
- platform/dbops/binaries/go/go/test/const6.go +30 -0
- platform/dbops/binaries/go/go/test/const7.go +78 -0
- platform/dbops/binaries/go/go/test/const8.go +36 -0
- platform/dbops/binaries/go/go/test/convT2X.go +195 -0
- platform/dbops/binaries/go/go/test/convert.go +46 -0
- platform/dbops/binaries/go/go/test/convert1.go +99 -0
- platform/dbops/binaries/go/go/test/convert2.go +329 -0
- platform/dbops/binaries/go/go/test/convert3.go +29 -0
- platform/dbops/binaries/go/go/test/convert4.go +108 -0
- platform/dbops/binaries/go/go/test/convinline.go +194 -0
- platform/dbops/binaries/go/go/test/convlit.go +74 -0
- platform/dbops/binaries/go/go/test/convlit1.go +20 -0
- platform/dbops/binaries/go/go/test/copy.go +351 -0
platform/dbops/binaries/go/go/test/blank.go
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test behavior of the blank identifier (_).
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"os"
|
| 13 |
+
"unsafe"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
import _ "fmt"
|
| 17 |
+
|
| 18 |
+
var call string
|
| 19 |
+
|
| 20 |
+
type T struct {
|
| 21 |
+
_, _, _ int
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
func (T) _() {
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
func (T) _() {
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
type U struct {
|
| 31 |
+
_ struct{ a, b, c int }
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const (
|
| 35 |
+
c0 = iota
|
| 36 |
+
_
|
| 37 |
+
_
|
| 38 |
+
_
|
| 39 |
+
c4
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
var ints = []string{
|
| 43 |
+
"1",
|
| 44 |
+
"2",
|
| 45 |
+
"3",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func f() (int, int) {
|
| 49 |
+
call += "f"
|
| 50 |
+
return 1, 2
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
func g() (float64, float64) {
|
| 54 |
+
call += "g"
|
| 55 |
+
return 3, 4
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func h(_ int, _ float64) {
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func i() int {
|
| 62 |
+
call += "i"
|
| 63 |
+
return 23
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
var _ = i()
|
| 67 |
+
|
| 68 |
+
func main() {
|
| 69 |
+
if call != "i" {
|
| 70 |
+
panic("init did not run")
|
| 71 |
+
}
|
| 72 |
+
call = ""
|
| 73 |
+
_, _ = f()
|
| 74 |
+
a, _ := f()
|
| 75 |
+
if a != 1 {
|
| 76 |
+
panic(a)
|
| 77 |
+
}
|
| 78 |
+
b, _ := g()
|
| 79 |
+
if b != 3 {
|
| 80 |
+
panic(b)
|
| 81 |
+
}
|
| 82 |
+
_, a = f()
|
| 83 |
+
if a != 2 {
|
| 84 |
+
panic(a)
|
| 85 |
+
}
|
| 86 |
+
_, b = g()
|
| 87 |
+
if b != 4 {
|
| 88 |
+
panic(b)
|
| 89 |
+
}
|
| 90 |
+
_ = i()
|
| 91 |
+
if call != "ffgfgi" {
|
| 92 |
+
panic(call)
|
| 93 |
+
}
|
| 94 |
+
if c4 != 4 {
|
| 95 |
+
panic(c4)
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
out := ""
|
| 99 |
+
for _, s := range ints {
|
| 100 |
+
out += s
|
| 101 |
+
}
|
| 102 |
+
if out != "123" {
|
| 103 |
+
panic(out)
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
sum := 0
|
| 107 |
+
for s := range ints {
|
| 108 |
+
sum += s
|
| 109 |
+
}
|
| 110 |
+
if sum != 3 {
|
| 111 |
+
panic(sum)
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// go.tools/ssa/interp cannot support unsafe.Pointer.
|
| 115 |
+
if os.Getenv("GOSSAINTERP") == "" {
|
| 116 |
+
type T1 struct{ x, y, z int }
|
| 117 |
+
t1 := *(*T)(unsafe.Pointer(&T1{1, 2, 3}))
|
| 118 |
+
t2 := *(*T)(unsafe.Pointer(&T1{4, 5, 6}))
|
| 119 |
+
if t1 != t2 {
|
| 120 |
+
panic("T{} != T{}")
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
var u1, u2 interface{}
|
| 124 |
+
u1 = *(*U)(unsafe.Pointer(&T1{1, 2, 3}))
|
| 125 |
+
u2 = *(*U)(unsafe.Pointer(&T1{4, 5, 6}))
|
| 126 |
+
if u1 != u2 {
|
| 127 |
+
panic("U{} != U{}")
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
h(a, b)
|
| 132 |
+
|
| 133 |
+
m()
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
type I interface {
|
| 137 |
+
M(_ int, y int)
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
type TI struct{}
|
| 141 |
+
|
| 142 |
+
func (_ TI) M(x int, y int) {
|
| 143 |
+
if x != y {
|
| 144 |
+
println("invalid M call:", x, y)
|
| 145 |
+
panic("bad M")
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
var fp = func(_ int, y int) {}
|
| 150 |
+
|
| 151 |
+
func init() {
|
| 152 |
+
fp = fp1
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
func fp1(x, y int) {
|
| 156 |
+
if x != y {
|
| 157 |
+
println("invalid fp1 call:", x, y)
|
| 158 |
+
panic("bad fp1")
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
func m() {
|
| 163 |
+
var i I
|
| 164 |
+
|
| 165 |
+
i = TI{}
|
| 166 |
+
i.M(1, 1)
|
| 167 |
+
i.M(2, 2)
|
| 168 |
+
|
| 169 |
+
fp(1, 1)
|
| 170 |
+
fp(2, 2)
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// useless but legal
|
| 174 |
+
var _ int = 1
|
| 175 |
+
var _ = 2
|
| 176 |
+
var _, _ = 3, 4
|
| 177 |
+
|
| 178 |
+
const _ = 3
|
| 179 |
+
const _, _ = 4, 5
|
| 180 |
+
|
| 181 |
+
type _ int
|
| 182 |
+
|
| 183 |
+
func _() {
|
| 184 |
+
panic("oops")
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
func ff() {
|
| 188 |
+
var _ int = 1
|
| 189 |
+
}
|
platform/dbops/binaries/go/go/test/blank1.go
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test that incorrect uses of the blank identifier are caught.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package _ // ERROR "invalid package name"
|
| 11 |
+
|
| 12 |
+
var t struct {
|
| 13 |
+
_ int
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
func (x int) _() { // ERROR "methods on non-local type"
|
| 17 |
+
println(x)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type T struct {
|
| 21 |
+
_ []int
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
func main() {
|
| 25 |
+
_() // ERROR "cannot use .* as value"
|
| 26 |
+
x := _+1 // ERROR "cannot use .* as value"
|
| 27 |
+
_ = x
|
| 28 |
+
_ = t._ // ERROR "cannot refer to blank field|invalid use of|t._ undefined"
|
| 29 |
+
|
| 30 |
+
var v1, v2 T
|
| 31 |
+
_ = v1 == v2 // ERROR "cannot be compared|non-comparable|cannot compare v1 == v2"
|
| 32 |
+
}
|
platform/dbops/binaries/go/go/test/bom.go
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// runoutput
|
| 2 |
+
|
| 3 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test source file beginning with a byte order mark.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"fmt"
|
| 13 |
+
"strings"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
func main() {
|
| 17 |
+
prog = strings.Replace(prog, "BOM", "\uFEFF", -1)
|
| 18 |
+
fmt.Print(prog)
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
var prog = `BOM
|
| 22 |
+
package main
|
| 23 |
+
|
| 24 |
+
func main() {
|
| 25 |
+
}
|
| 26 |
+
`
|
platform/dbops/binaries/go/go/test/bombad.go
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2012 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Here for reference, but hard to test automatically
|
| 8 |
+
// because the BOM muddles the
|
| 9 |
+
// processing done by ../run.
|
| 10 |
+
|
| 11 |
+
package main
|
| 12 |
+
|
| 13 |
+
func main() {
|
| 14 |
+
// There's a bom here. // ERROR "BOM"
|
| 15 |
+
// And here. // ERROR "BOM"
|
| 16 |
+
/* And here.*/ // ERROR "BOM"
|
| 17 |
+
println("hi there") // and here // ERROR "BOM"
|
| 18 |
+
}
|
platform/dbops/binaries/go/go/test/bounds.go
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck -0 -m -l
|
| 2 |
+
|
| 3 |
+
// Copyright 2012 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test, using compiler diagnostic flags, that bounds check elimination
|
| 8 |
+
// is eliminating the correct checks.
|
| 9 |
+
|
| 10 |
+
package foo
|
| 11 |
+
|
| 12 |
+
var (
|
| 13 |
+
s []int
|
| 14 |
+
|
| 15 |
+
a1 [1]int
|
| 16 |
+
a1k [1000]int
|
| 17 |
+
a100k [100000]int
|
| 18 |
+
|
| 19 |
+
p1 *[1]int
|
| 20 |
+
p1k *[1000]int
|
| 21 |
+
p100k *[100000]int
|
| 22 |
+
|
| 23 |
+
i int
|
| 24 |
+
ui uint
|
| 25 |
+
i8 int8
|
| 26 |
+
ui8 uint8
|
| 27 |
+
i16 int16
|
| 28 |
+
ui16 uint16
|
| 29 |
+
i32 int32
|
| 30 |
+
ui32 uint32
|
| 31 |
+
i64 int64
|
| 32 |
+
ui64 uint64
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
func main() {
|
| 36 |
+
// Most things need checks.
|
| 37 |
+
use(s[i])
|
| 38 |
+
use(a1[i])
|
| 39 |
+
use(a1k[i])
|
| 40 |
+
use(a100k[i])
|
| 41 |
+
use(p1[i])
|
| 42 |
+
use(p1k[i])
|
| 43 |
+
use(p100k[i])
|
| 44 |
+
|
| 45 |
+
use(s[ui])
|
| 46 |
+
use(a1[ui])
|
| 47 |
+
use(a1k[ui])
|
| 48 |
+
use(a100k[ui])
|
| 49 |
+
use(p1[ui])
|
| 50 |
+
use(p1k[ui])
|
| 51 |
+
use(p100k[ui])
|
| 52 |
+
|
| 53 |
+
use(s[i8])
|
| 54 |
+
use(a1[i8])
|
| 55 |
+
use(a1k[i8])
|
| 56 |
+
use(a100k[i8])
|
| 57 |
+
use(p1[i8])
|
| 58 |
+
use(p1k[i8])
|
| 59 |
+
use(p100k[i8])
|
| 60 |
+
|
| 61 |
+
// Unsigned 8-bit numbers don't need checks for len >= 2⁸.
|
| 62 |
+
use(s[ui8])
|
| 63 |
+
use(a1[ui8])
|
| 64 |
+
use(a1k[ui8]) // ERROR "index bounds check elided"
|
| 65 |
+
use(a100k[ui8]) // ERROR "index bounds check elided"
|
| 66 |
+
use(p1[ui8])
|
| 67 |
+
use(p1k[ui8]) // ERROR "index bounds check elided"
|
| 68 |
+
use(p100k[ui8]) // ERROR "index bounds check elided"
|
| 69 |
+
|
| 70 |
+
use(s[i16])
|
| 71 |
+
use(a1[i16])
|
| 72 |
+
use(a1k[i16])
|
| 73 |
+
use(a100k[i16])
|
| 74 |
+
use(p1[i16])
|
| 75 |
+
use(p1k[i16])
|
| 76 |
+
use(p100k[i16])
|
| 77 |
+
|
| 78 |
+
// Unsigned 16-bit numbers don't need checks for len >= 2¹⁶.
|
| 79 |
+
use(s[ui16])
|
| 80 |
+
use(a1[ui16])
|
| 81 |
+
use(a1k[ui16])
|
| 82 |
+
use(a100k[ui16]) // ERROR "index bounds check elided"
|
| 83 |
+
use(p1[ui16])
|
| 84 |
+
use(p1k[ui16])
|
| 85 |
+
use(p100k[ui16]) // ERROR "index bounds check elided"
|
| 86 |
+
|
| 87 |
+
use(s[i32])
|
| 88 |
+
use(a1[i32])
|
| 89 |
+
use(a1k[i32])
|
| 90 |
+
use(a100k[i32])
|
| 91 |
+
use(p1[i32])
|
| 92 |
+
use(p1k[i32])
|
| 93 |
+
use(p100k[i32])
|
| 94 |
+
|
| 95 |
+
use(s[ui32])
|
| 96 |
+
use(a1[ui32])
|
| 97 |
+
use(a1k[ui32])
|
| 98 |
+
use(a100k[ui32])
|
| 99 |
+
use(p1[ui32])
|
| 100 |
+
use(p1k[ui32])
|
| 101 |
+
use(p100k[ui32])
|
| 102 |
+
|
| 103 |
+
use(s[i64])
|
| 104 |
+
use(a1[i64])
|
| 105 |
+
use(a1k[i64])
|
| 106 |
+
use(a100k[i64])
|
| 107 |
+
use(p1[i64])
|
| 108 |
+
use(p1k[i64])
|
| 109 |
+
use(p100k[i64])
|
| 110 |
+
|
| 111 |
+
use(s[ui64])
|
| 112 |
+
use(a1[ui64])
|
| 113 |
+
use(a1k[ui64])
|
| 114 |
+
use(a100k[ui64])
|
| 115 |
+
use(p1[ui64])
|
| 116 |
+
use(p1k[ui64])
|
| 117 |
+
use(p100k[ui64])
|
| 118 |
+
|
| 119 |
+
// Mod truncates the maximum value to one less than the argument,
|
| 120 |
+
// but signed mod can be negative, so only unsigned mod counts.
|
| 121 |
+
use(s[i%999])
|
| 122 |
+
use(a1[i%999])
|
| 123 |
+
use(a1k[i%999])
|
| 124 |
+
use(a100k[i%999])
|
| 125 |
+
use(p1[i%999])
|
| 126 |
+
use(p1k[i%999])
|
| 127 |
+
use(p100k[i%999])
|
| 128 |
+
|
| 129 |
+
use(s[ui%999])
|
| 130 |
+
use(a1[ui%999])
|
| 131 |
+
use(a1k[ui%999]) // ERROR "index bounds check elided"
|
| 132 |
+
use(a100k[ui%999]) // ERROR "index bounds check elided"
|
| 133 |
+
use(p1[ui%999])
|
| 134 |
+
use(p1k[ui%999]) // ERROR "index bounds check elided"
|
| 135 |
+
use(p100k[ui%999]) // ERROR "index bounds check elided"
|
| 136 |
+
|
| 137 |
+
use(s[i%1000])
|
| 138 |
+
use(a1[i%1000])
|
| 139 |
+
use(a1k[i%1000])
|
| 140 |
+
use(a100k[i%1000])
|
| 141 |
+
use(p1[i%1000])
|
| 142 |
+
use(p1k[i%1000])
|
| 143 |
+
use(p100k[i%1000])
|
| 144 |
+
|
| 145 |
+
use(s[ui%1000])
|
| 146 |
+
use(a1[ui%1000])
|
| 147 |
+
use(a1k[ui%1000]) // ERROR "index bounds check elided"
|
| 148 |
+
use(a100k[ui%1000]) // ERROR "index bounds check elided"
|
| 149 |
+
use(p1[ui%1000])
|
| 150 |
+
use(p1k[ui%1000]) // ERROR "index bounds check elided"
|
| 151 |
+
use(p100k[ui%1000]) // ERROR "index bounds check elided"
|
| 152 |
+
|
| 153 |
+
use(s[i%1001])
|
| 154 |
+
use(a1[i%1001])
|
| 155 |
+
use(a1k[i%1001])
|
| 156 |
+
use(a100k[i%1001])
|
| 157 |
+
use(p1[i%1001])
|
| 158 |
+
use(p1k[i%1001])
|
| 159 |
+
use(p100k[i%1001])
|
| 160 |
+
|
| 161 |
+
use(s[ui%1001])
|
| 162 |
+
use(a1[ui%1001])
|
| 163 |
+
use(a1k[ui%1001])
|
| 164 |
+
use(a100k[ui%1001]) // ERROR "index bounds check elided"
|
| 165 |
+
use(p1[ui%1001])
|
| 166 |
+
use(p1k[ui%1001])
|
| 167 |
+
use(p100k[ui%1001]) // ERROR "index bounds check elided"
|
| 168 |
+
|
| 169 |
+
// Bitwise and truncates the maximum value to the mask value.
|
| 170 |
+
// The result (for a positive mask) cannot be negative, so elision
|
| 171 |
+
// applies to both signed and unsigned indexes.
|
| 172 |
+
use(s[i&999])
|
| 173 |
+
use(a1[i&999])
|
| 174 |
+
use(a1k[i&999]) // ERROR "index bounds check elided"
|
| 175 |
+
use(a100k[i&999]) // ERROR "index bounds check elided"
|
| 176 |
+
use(p1[i&999])
|
| 177 |
+
use(p1k[i&999]) // ERROR "index bounds check elided"
|
| 178 |
+
use(p100k[i&999]) // ERROR "index bounds check elided"
|
| 179 |
+
|
| 180 |
+
use(s[ui&999])
|
| 181 |
+
use(a1[ui&999])
|
| 182 |
+
use(a1k[ui&999]) // ERROR "index bounds check elided"
|
| 183 |
+
use(a100k[ui&999]) // ERROR "index bounds check elided"
|
| 184 |
+
use(p1[ui&999])
|
| 185 |
+
use(p1k[ui&999]) // ERROR "index bounds check elided"
|
| 186 |
+
use(p100k[ui&999]) // ERROR "index bounds check elided"
|
| 187 |
+
|
| 188 |
+
use(s[i&1000])
|
| 189 |
+
use(a1[i&1000])
|
| 190 |
+
use(a1k[i&1000])
|
| 191 |
+
use(a100k[i&1000]) // ERROR "index bounds check elided"
|
| 192 |
+
use(p1[i&1000])
|
| 193 |
+
use(p1k[i&1000])
|
| 194 |
+
use(p100k[i&1000]) // ERROR "index bounds check elided"
|
| 195 |
+
|
| 196 |
+
use(s[ui&1000])
|
| 197 |
+
use(a1[ui&1000])
|
| 198 |
+
use(a1k[ui&1000])
|
| 199 |
+
use(a100k[ui&1000]) // ERROR "index bounds check elided"
|
| 200 |
+
use(p1[ui&1000])
|
| 201 |
+
use(p1k[ui&1000])
|
| 202 |
+
use(p100k[ui&1000]) // ERROR "index bounds check elided"
|
| 203 |
+
|
| 204 |
+
use(a1[i&^-1]) // ERROR "index bounds check elided"
|
| 205 |
+
use(a1[i&^0])
|
| 206 |
+
use(a1[i&^-2])
|
| 207 |
+
use(a1[i&^1])
|
| 208 |
+
use(a1k[i&^-1]) // ERROR "index bounds check elided"
|
| 209 |
+
use(a1k[i&^0])
|
| 210 |
+
use(a1k[i&^-2]) // ERROR "index bounds check elided"
|
| 211 |
+
use(a1k[i&^1])
|
| 212 |
+
use(a1k[i8&^0])
|
| 213 |
+
use(a1k[i8&^-128]) // ERROR "index bounds check elided"
|
| 214 |
+
use(a1k[ui8&^1]) // ERROR "index bounds check elided"
|
| 215 |
+
use(a1k[ui16&^0xf000])
|
| 216 |
+
use(a1k[ui16&^0xff00]) // ERROR "index bounds check elided"
|
| 217 |
+
|
| 218 |
+
// Right shift cuts the effective number of bits in the index,
|
| 219 |
+
// but only for unsigned (signed stays negative).
|
| 220 |
+
use(s[i32>>22])
|
| 221 |
+
use(a1[i32>>22])
|
| 222 |
+
use(a1k[i32>>22])
|
| 223 |
+
use(a100k[i32>>22])
|
| 224 |
+
use(p1[i32>>22])
|
| 225 |
+
use(p1k[i32>>22])
|
| 226 |
+
use(p100k[i32>>22])
|
| 227 |
+
|
| 228 |
+
use(s[ui32>>22])
|
| 229 |
+
use(a1[ui32>>22])
|
| 230 |
+
use(a1k[ui32>>22])
|
| 231 |
+
use(a100k[ui32>>22]) // ERROR "index bounds check elided"
|
| 232 |
+
use(p1[ui32>>22])
|
| 233 |
+
use(p1k[ui32>>22])
|
| 234 |
+
use(p100k[ui32>>22]) // ERROR "index bounds check elided"
|
| 235 |
+
|
| 236 |
+
use(s[i32>>23])
|
| 237 |
+
use(a1[i32>>23])
|
| 238 |
+
use(a1k[i32>>23])
|
| 239 |
+
use(a100k[i32>>23])
|
| 240 |
+
use(p1[i32>>23])
|
| 241 |
+
use(p1k[i32>>23])
|
| 242 |
+
use(p100k[i32>>23])
|
| 243 |
+
|
| 244 |
+
use(s[ui32>>23])
|
| 245 |
+
use(a1[ui32>>23])
|
| 246 |
+
use(a1k[ui32>>23]) // ERROR "index bounds check elided"
|
| 247 |
+
use(a100k[ui32>>23]) // ERROR "index bounds check elided"
|
| 248 |
+
use(p1[ui32>>23])
|
| 249 |
+
use(p1k[ui32>>23]) // ERROR "index bounds check elided"
|
| 250 |
+
use(p100k[ui32>>23]) // ERROR "index bounds check elided"
|
| 251 |
+
|
| 252 |
+
// Division cuts the range like right shift does.
|
| 253 |
+
use(s[i/1e6])
|
| 254 |
+
use(a1[i/1e6])
|
| 255 |
+
use(a1k[i/1e6])
|
| 256 |
+
use(a100k[i/1e6])
|
| 257 |
+
use(p1[i/1e6])
|
| 258 |
+
use(p1k[i/1e6])
|
| 259 |
+
use(p100k[i/1e6])
|
| 260 |
+
|
| 261 |
+
use(s[ui/1e6])
|
| 262 |
+
use(a1[ui/1e6])
|
| 263 |
+
use(a1k[ui/1e6])
|
| 264 |
+
use(p1[ui/1e6])
|
| 265 |
+
use(p1k[ui/1e6])
|
| 266 |
+
|
| 267 |
+
use(s[i/1e7])
|
| 268 |
+
use(a1[i/1e7])
|
| 269 |
+
use(a1k[i/1e7])
|
| 270 |
+
use(a100k[i/1e7])
|
| 271 |
+
use(p1[i/1e7])
|
| 272 |
+
use(p1k[i/1e7])
|
| 273 |
+
use(p100k[i/1e7])
|
| 274 |
+
|
| 275 |
+
use(s[ui/1e7])
|
| 276 |
+
use(a1[ui/1e7])
|
| 277 |
+
use(p1[ui/1e7])
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
var sum int
|
| 281 |
+
|
| 282 |
+
func use(x int) {
|
| 283 |
+
sum += x
|
| 284 |
+
}
|
platform/dbops/binaries/go/go/test/cannotassign.go
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2020 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test "cannot assign" errors
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
func main() {
|
| 12 |
+
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\))?"
|
| 15 |
+
|
| 16 |
+
const n int = 1
|
| 17 |
+
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\))?"
|
| 21 |
+
|
| 22 |
+
var m map[int]struct{ n int }
|
| 23 |
+
m[0].n = 7 // ERROR "cannot assign to struct field .* in map$"
|
| 24 |
+
|
| 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\{\}"
|
| 30 |
+
|
| 31 |
+
var x int = 7
|
| 32 |
+
x + 1 = 7 // ERROR "cannot assign to x \+ 1"
|
| 33 |
+
}
|
platform/dbops/binaries/go/go/test/chancap.go
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test the cap predeclared function applied to channels.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"strings"
|
| 13 |
+
"unsafe"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
type T chan int
|
| 17 |
+
|
| 18 |
+
const ptrSize = unsafe.Sizeof((*byte)(nil))
|
| 19 |
+
|
| 20 |
+
func main() {
|
| 21 |
+
c := make(T, 10)
|
| 22 |
+
if len(c) != 0 || cap(c) != 10 {
|
| 23 |
+
println("chan len/cap ", len(c), cap(c), " want 0 10")
|
| 24 |
+
panic("fail")
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
for i := 0; i < 3; i++ {
|
| 28 |
+
c <- i
|
| 29 |
+
}
|
| 30 |
+
if len(c) != 3 || cap(c) != 10 {
|
| 31 |
+
println("chan len/cap ", len(c), cap(c), " want 3 10")
|
| 32 |
+
panic("fail")
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
c = make(T)
|
| 36 |
+
if len(c) != 0 || cap(c) != 0 {
|
| 37 |
+
println("chan len/cap ", len(c), cap(c), " want 0 0")
|
| 38 |
+
panic("fail")
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
n := -1
|
| 42 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
|
| 43 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
|
| 44 |
+
if ptrSize == 8 {
|
| 45 |
+
// Test mem > maxAlloc
|
| 46 |
+
var n2 int64 = 1 << 59
|
| 47 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
|
| 48 |
+
// Test elem.size*cap overflow
|
| 49 |
+
n2 = 1<<63 - 1
|
| 50 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
|
| 51 |
+
} else {
|
| 52 |
+
n = 1<<31 - 1
|
| 53 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
|
| 54 |
+
shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func shouldPanic(str string, f func()) {
|
| 59 |
+
defer func() {
|
| 60 |
+
err := recover()
|
| 61 |
+
if err == nil {
|
| 62 |
+
panic("did not panic")
|
| 63 |
+
}
|
| 64 |
+
s := err.(error).Error()
|
| 65 |
+
if !strings.Contains(s, str) {
|
| 66 |
+
panic("got panic " + s + ", want " + str)
|
| 67 |
+
}
|
| 68 |
+
}()
|
| 69 |
+
|
| 70 |
+
f()
|
| 71 |
+
}
|
platform/dbops/binaries/go/go/test/chanlinear.go
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
//go:build darwin || linux
|
| 4 |
+
|
| 5 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 6 |
+
// Use of this source code is governed by a BSD-style
|
| 7 |
+
// license that can be found in the LICENSE file.
|
| 8 |
+
|
| 9 |
+
// Test that dequeuing from a pending channel doesn't
|
| 10 |
+
// take linear time.
|
| 11 |
+
|
| 12 |
+
package main
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"runtime"
|
| 17 |
+
"time"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
// checkLinear asserts that the running time of f(n) is in O(n).
|
| 21 |
+
// tries is the initial number of iterations.
|
| 22 |
+
func checkLinear(typ string, tries int, f func(n int)) {
|
| 23 |
+
// Depending on the machine and OS, this test might be too fast
|
| 24 |
+
// to measure with accurate enough granularity. On failure,
|
| 25 |
+
// make it run longer, hoping that the timing granularity
|
| 26 |
+
// is eventually sufficient.
|
| 27 |
+
|
| 28 |
+
timeF := func(n int) time.Duration {
|
| 29 |
+
t1 := time.Now()
|
| 30 |
+
f(n)
|
| 31 |
+
return time.Since(t1)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
t0 := time.Now()
|
| 35 |
+
|
| 36 |
+
n := tries
|
| 37 |
+
fails := 0
|
| 38 |
+
for {
|
| 39 |
+
runtime.GC()
|
| 40 |
+
t1 := timeF(n)
|
| 41 |
+
runtime.GC()
|
| 42 |
+
t2 := timeF(2 * n)
|
| 43 |
+
|
| 44 |
+
// should be 2x (linear); allow up to 3x
|
| 45 |
+
if t2 < 3*t1 {
|
| 46 |
+
if false {
|
| 47 |
+
fmt.Println(typ, "\t", time.Since(t0))
|
| 48 |
+
}
|
| 49 |
+
return
|
| 50 |
+
}
|
| 51 |
+
// If n ops run in under a second and the ratio
|
| 52 |
+
// doesn't work out, make n bigger, trying to reduce
|
| 53 |
+
// the effect that a constant amount of overhead has
|
| 54 |
+
// on the computed ratio.
|
| 55 |
+
if t1 < 1*time.Second {
|
| 56 |
+
n *= 2
|
| 57 |
+
continue
|
| 58 |
+
}
|
| 59 |
+
// Once the test runs long enough for n ops,
|
| 60 |
+
// try to get the right ratio at least once.
|
| 61 |
+
// If five in a row all fail, give up.
|
| 62 |
+
if fails++; fails >= 5 {
|
| 63 |
+
panic(fmt.Sprintf("%s: too slow: %d channels: %v; %d channels: %v\n",
|
| 64 |
+
typ, n, t1, 2*n, t2))
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
func main() {
|
| 70 |
+
checkLinear("chanSelect", 1000, func(n int) {
|
| 71 |
+
const messages = 10
|
| 72 |
+
c := make(chan bool) // global channel
|
| 73 |
+
var a []chan bool // local channels for each goroutine
|
| 74 |
+
for i := 0; i < n; i++ {
|
| 75 |
+
d := make(chan bool)
|
| 76 |
+
a = append(a, d)
|
| 77 |
+
go func() {
|
| 78 |
+
for j := 0; j < messages; j++ {
|
| 79 |
+
// queue ourselves on the global channel
|
| 80 |
+
select {
|
| 81 |
+
case <-c:
|
| 82 |
+
case <-d:
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}()
|
| 86 |
+
}
|
| 87 |
+
for i := 0; i < messages; i++ {
|
| 88 |
+
// wake each goroutine up, forcing it to dequeue and then enqueue
|
| 89 |
+
// on the global channel.
|
| 90 |
+
for _, d := range a {
|
| 91 |
+
d <- true
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
})
|
| 95 |
+
}
|
platform/dbops/binaries/go/go/test/char_lit.go
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test character literal syntax.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import "os"
|
| 12 |
+
|
| 13 |
+
func main() {
|
| 14 |
+
var i uint64 =
|
| 15 |
+
' ' +
|
| 16 |
+
'a' +
|
| 17 |
+
'ä' +
|
| 18 |
+
'本' +
|
| 19 |
+
'\a' +
|
| 20 |
+
'\b' +
|
| 21 |
+
'\f' +
|
| 22 |
+
'\n' +
|
| 23 |
+
'\r' +
|
| 24 |
+
'\t' +
|
| 25 |
+
'\v' +
|
| 26 |
+
'\\' +
|
| 27 |
+
'\'' +
|
| 28 |
+
'\000' +
|
| 29 |
+
'\123' +
|
| 30 |
+
'\x00' +
|
| 31 |
+
'\xca' +
|
| 32 |
+
'\xFE' +
|
| 33 |
+
'\u0123' +
|
| 34 |
+
'\ubabe' +
|
| 35 |
+
'\U0010FFFF' +
|
| 36 |
+
'\U000ebabe'
|
| 37 |
+
if '\U000ebabe' != 0x000ebabe {
|
| 38 |
+
print("ebabe wrong\n")
|
| 39 |
+
os.Exit(1)
|
| 40 |
+
}
|
| 41 |
+
if i != 0x20e213 {
|
| 42 |
+
print("number is ", i, " should be ", 0x20e213, "\n")
|
| 43 |
+
os.Exit(1)
|
| 44 |
+
}
|
| 45 |
+
}
|
platform/dbops/binaries/go/go/test/char_lit1.go
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck -d=panic
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that illegal character literals are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
const (
|
| 13 |
+
// check that surrogate pair elements are invalid
|
| 14 |
+
// (d800-dbff, dc00-dfff).
|
| 15 |
+
_ = '\ud7ff' // ok
|
| 16 |
+
_ = '\ud800' // ERROR "Unicode|unicode"
|
| 17 |
+
_ = "\U0000D999" // ERROR "Unicode|unicode"
|
| 18 |
+
_ = '\udc01' // ERROR "Unicode|unicode"
|
| 19 |
+
_ = '\U0000dddd' // ERROR "Unicode|unicode"
|
| 20 |
+
_ = '\udfff' // ERROR "Unicode|unicode"
|
| 21 |
+
_ = '\ue000' // ok
|
| 22 |
+
_ = '\U0010ffff' // ok
|
| 23 |
+
_ = '\U00110000' // ERROR "Unicode|unicode"
|
| 24 |
+
_ = "abc\U0010ffffdef" // ok
|
| 25 |
+
_ = "abc\U00110000def" // ERROR "Unicode|unicode"
|
| 26 |
+
_ = '\Uffffffff' // ERROR "Unicode|unicode"
|
| 27 |
+
)
|
| 28 |
+
|
platform/dbops/binaries/go/go/test/checkbce.go
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck -0 -d=ssa/check_bce/debug=3
|
| 2 |
+
|
| 3 |
+
//go:build amd64 && !gcflags_noopt
|
| 4 |
+
|
| 5 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 6 |
+
// Use of this source code is governed by a BSD-style
|
| 7 |
+
// license that can be found in the LICENSE file.
|
| 8 |
+
|
| 9 |
+
// Test that the compiler does bounds check elimination as expected.
|
| 10 |
+
// This avoids accidental regressions.
|
| 11 |
+
|
| 12 |
+
package main
|
| 13 |
+
|
| 14 |
+
import "encoding/binary"
|
| 15 |
+
|
| 16 |
+
func f0(a []int) {
|
| 17 |
+
a[0] = 1 // ERROR "Found IsInBounds$"
|
| 18 |
+
a[0] = 1
|
| 19 |
+
a[6] = 1 // ERROR "Found IsInBounds$"
|
| 20 |
+
a[6] = 1
|
| 21 |
+
a[5] = 1
|
| 22 |
+
a[5] = 1
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
func f1(a [256]int, i int) {
|
| 26 |
+
var j int
|
| 27 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 28 |
+
j = i % 256
|
| 29 |
+
useInt(a[j]) // ERROR "Found IsInBounds$"
|
| 30 |
+
j = i & 255
|
| 31 |
+
useInt(a[j])
|
| 32 |
+
j = i & 17
|
| 33 |
+
useInt(a[j])
|
| 34 |
+
|
| 35 |
+
if 4 <= i && i < len(a) {
|
| 36 |
+
useInt(a[i])
|
| 37 |
+
useInt(a[i-1])
|
| 38 |
+
useInt(a[i-4])
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
func f2(a [256]int, i uint) {
|
| 43 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 44 |
+
j := i % 256
|
| 45 |
+
useInt(a[j])
|
| 46 |
+
j = i & 255
|
| 47 |
+
useInt(a[j])
|
| 48 |
+
j = i & 17
|
| 49 |
+
useInt(a[j])
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func f2a(a [35]int, i uint8) {
|
| 53 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 54 |
+
j := i & 34
|
| 55 |
+
useInt(a[j])
|
| 56 |
+
j = i & 17
|
| 57 |
+
useInt(a[j])
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
func f2b(a [35]int, i uint16) {
|
| 61 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 62 |
+
j := i & 34
|
| 63 |
+
useInt(a[j])
|
| 64 |
+
j = i & 17
|
| 65 |
+
useInt(a[j])
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
func f2c(a [35]int, i uint32) {
|
| 69 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 70 |
+
j := i & 34
|
| 71 |
+
useInt(a[j])
|
| 72 |
+
j = i & 17
|
| 73 |
+
useInt(a[j])
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
func f3(a [256]int, i uint8) {
|
| 77 |
+
useInt(a[i])
|
| 78 |
+
useInt(a[i+10])
|
| 79 |
+
useInt(a[i+14])
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
func f4(a [27]int, i uint8) {
|
| 83 |
+
useInt(a[i%15])
|
| 84 |
+
useInt(a[i%19])
|
| 85 |
+
useInt(a[i%27])
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
func f5(a []int) {
|
| 89 |
+
if len(a) > 5 {
|
| 90 |
+
useInt(a[5])
|
| 91 |
+
useSlice(a[6:])
|
| 92 |
+
useSlice(a[:6])
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
func f6(a [32]int, b [64]int, i int) {
|
| 97 |
+
useInt(a[uint32(i*0x07C4ACDD)>>27])
|
| 98 |
+
useInt(b[uint64(i*0x07C4ACDD)>>58])
|
| 99 |
+
useInt(a[uint(i*0x07C4ACDD)>>59])
|
| 100 |
+
|
| 101 |
+
// The following bounds should not be removed because they can overflow.
|
| 102 |
+
useInt(a[uint32(i*0x106297f105d0cc86)>>26]) // ERROR "Found IsInBounds$"
|
| 103 |
+
useInt(b[uint64(i*0x106297f105d0cc86)>>57]) // ERROR "Found IsInBounds$"
|
| 104 |
+
useInt(a[int32(i*0x106297f105d0cc86)>>26]) // ERROR "Found IsInBounds$"
|
| 105 |
+
useInt(b[int64(i*0x106297f105d0cc86)>>57]) // ERROR "Found IsInBounds$"
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
func g1(a []int) {
|
| 109 |
+
for i := range a {
|
| 110 |
+
a[i] = i
|
| 111 |
+
useSlice(a[:i+1])
|
| 112 |
+
useSlice(a[:i])
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
func g2(a []int) {
|
| 117 |
+
useInt(a[3]) // ERROR "Found IsInBounds$"
|
| 118 |
+
useInt(a[2])
|
| 119 |
+
useInt(a[1])
|
| 120 |
+
useInt(a[0])
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
func g3(a []int) {
|
| 124 |
+
for i := range a[:256] { // ERROR "Found IsSliceInBounds$"
|
| 125 |
+
useInt(a[i]) // ERROR "Found IsInBounds$"
|
| 126 |
+
}
|
| 127 |
+
b := a[:256]
|
| 128 |
+
for i := range b {
|
| 129 |
+
useInt(b[i])
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
func g4(a [100]int) {
|
| 134 |
+
for i := 10; i < 50; i++ {
|
| 135 |
+
useInt(a[i-10])
|
| 136 |
+
useInt(a[i])
|
| 137 |
+
useInt(a[i+25])
|
| 138 |
+
useInt(a[i+50])
|
| 139 |
+
|
| 140 |
+
// The following are out of bounds.
|
| 141 |
+
if a[0] == 0xdeadbeef {
|
| 142 |
+
// This is a trick to prohibit sccp to optimize out the following out of bound check
|
| 143 |
+
continue
|
| 144 |
+
}
|
| 145 |
+
useInt(a[i-11]) // ERROR "Found IsInBounds$"
|
| 146 |
+
useInt(a[i+51]) // ERROR "Found IsInBounds$"
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
func decode1(data []byte) (x uint64) {
|
| 151 |
+
for len(data) >= 32 {
|
| 152 |
+
x += binary.BigEndian.Uint64(data[:8])
|
| 153 |
+
x += binary.BigEndian.Uint64(data[8:16])
|
| 154 |
+
x += binary.BigEndian.Uint64(data[16:24])
|
| 155 |
+
x += binary.BigEndian.Uint64(data[24:32])
|
| 156 |
+
data = data[32:]
|
| 157 |
+
}
|
| 158 |
+
return x
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
func decode2(data []byte) (x uint64) {
|
| 162 |
+
// TODO(rasky): this should behave like decode1 and compile to no
|
| 163 |
+
// boundchecks. We're currently not able to remove all of them.
|
| 164 |
+
for len(data) >= 32 {
|
| 165 |
+
x += binary.BigEndian.Uint64(data)
|
| 166 |
+
data = data[8:]
|
| 167 |
+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
|
| 168 |
+
data = data[8:]
|
| 169 |
+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
|
| 170 |
+
data = data[8:]
|
| 171 |
+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
|
| 172 |
+
data = data[8:]
|
| 173 |
+
}
|
| 174 |
+
return x
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
//go:noinline
|
| 178 |
+
func useInt(a int) {
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
//go:noinline
|
| 182 |
+
func useSlice(a []int) {
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
func main() {
|
| 186 |
+
}
|
platform/dbops/binaries/go/go/test/clear.go
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
package main
|
| 8 |
+
|
| 9 |
+
import "math"
|
| 10 |
+
|
| 11 |
+
func checkClearSlice() {
|
| 12 |
+
s := []int{1, 2, 3}
|
| 13 |
+
clear(s)
|
| 14 |
+
for i := range s {
|
| 15 |
+
if s[i] != 0 {
|
| 16 |
+
panic("clear not zeroing slice elem")
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
clear([]int{})
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
func checkClearMap() {
|
| 24 |
+
m1 := make(map[int]int)
|
| 25 |
+
m1[0] = 0
|
| 26 |
+
m1[1] = 1
|
| 27 |
+
clear(m1)
|
| 28 |
+
if len(m1) != 0 {
|
| 29 |
+
panic("m1 is not cleared")
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// map contains NaN keys is also cleared.
|
| 33 |
+
m2 := make(map[float64]int)
|
| 34 |
+
m2[math.NaN()] = 1
|
| 35 |
+
m2[math.NaN()] = 1
|
| 36 |
+
clear(m2)
|
| 37 |
+
if len(m2) != 0 {
|
| 38 |
+
panic("m2 is not cleared")
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
clear(map[int]int{})
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
func main() {
|
| 45 |
+
checkClearSlice()
|
| 46 |
+
checkClearMap()
|
| 47 |
+
}
|
platform/dbops/binaries/go/go/test/clearfat.go
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// runoutput
|
| 2 |
+
|
| 3 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Check that {5,6,8,9}g/ggen.c:clearfat is zeroing the entire object.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"bytes"
|
| 13 |
+
"fmt"
|
| 14 |
+
"strconv"
|
| 15 |
+
"strings"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
const ntest = 1100
|
| 19 |
+
|
| 20 |
+
func main() {
|
| 21 |
+
var decls, calls bytes.Buffer
|
| 22 |
+
|
| 23 |
+
for i := 1; i <= ntest; i++ {
|
| 24 |
+
s := strconv.Itoa(i)
|
| 25 |
+
decls.WriteString(strings.Replace(decl, "$", s, -1))
|
| 26 |
+
calls.WriteString(strings.Replace("poison$()\n\tclearfat$()\n\t", "$", s, -1))
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
program = strings.Replace(program, "$DECLS", decls.String(), 1)
|
| 30 |
+
program = strings.Replace(program, "$CALLS", calls.String(), 1)
|
| 31 |
+
fmt.Print(program)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
var program = `package main
|
| 35 |
+
|
| 36 |
+
var count int
|
| 37 |
+
|
| 38 |
+
$DECLS
|
| 39 |
+
|
| 40 |
+
func main() {
|
| 41 |
+
$CALLS
|
| 42 |
+
if count != 0 {
|
| 43 |
+
println("failed", count, "case(s)")
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
`
|
| 47 |
+
|
| 48 |
+
const decl = `
|
| 49 |
+
func poison$() {
|
| 50 |
+
// Grow and poison the stack space that will be used by clearfat$
|
| 51 |
+
var t [2*$]byte
|
| 52 |
+
for i := range t {
|
| 53 |
+
t[i] = 0xff
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
func clearfat$() {
|
| 58 |
+
var t [$]byte
|
| 59 |
+
|
| 60 |
+
for _, x := range t {
|
| 61 |
+
if x != 0 {
|
| 62 |
+
// println("clearfat$: index", i, "expected 0, got", x)
|
| 63 |
+
count++
|
| 64 |
+
break
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
`
|
platform/dbops/binaries/go/go/test/closedchan.go
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test close(c), receive of closed channel.
|
| 8 |
+
//
|
| 9 |
+
// TODO(rsc): Doesn't check behavior of close(c) when there
|
| 10 |
+
// are blocked senders/receivers.
|
| 11 |
+
|
| 12 |
+
package main
|
| 13 |
+
|
| 14 |
+
import "os"
|
| 15 |
+
|
| 16 |
+
var failed bool
|
| 17 |
+
|
| 18 |
+
type Chan interface {
|
| 19 |
+
Send(int)
|
| 20 |
+
Nbsend(int) bool
|
| 21 |
+
Recv() (int)
|
| 22 |
+
Nbrecv() (int, bool)
|
| 23 |
+
Recv2() (int, bool)
|
| 24 |
+
Nbrecv2() (int, bool, bool)
|
| 25 |
+
Close()
|
| 26 |
+
Impl() string
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// direct channel operations when possible
|
| 30 |
+
type XChan chan int
|
| 31 |
+
|
| 32 |
+
func (c XChan) Send(x int) {
|
| 33 |
+
c <- x
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func (c XChan) Nbsend(x int) bool {
|
| 37 |
+
select {
|
| 38 |
+
case c <- x:
|
| 39 |
+
return true
|
| 40 |
+
default:
|
| 41 |
+
return false
|
| 42 |
+
}
|
| 43 |
+
panic("nbsend")
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func (c XChan) Recv() int {
|
| 47 |
+
return <-c
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
func (c XChan) Nbrecv() (int, bool) {
|
| 51 |
+
select {
|
| 52 |
+
case x := <-c:
|
| 53 |
+
return x, true
|
| 54 |
+
default:
|
| 55 |
+
return 0, false
|
| 56 |
+
}
|
| 57 |
+
panic("nbrecv")
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
func (c XChan) Recv2() (int, bool) {
|
| 61 |
+
x, ok := <-c
|
| 62 |
+
return x, ok
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func (c XChan) Nbrecv2() (int, bool, bool) {
|
| 66 |
+
select {
|
| 67 |
+
case x, ok := <-c:
|
| 68 |
+
return x, ok, true
|
| 69 |
+
default:
|
| 70 |
+
return 0, false, false
|
| 71 |
+
}
|
| 72 |
+
panic("nbrecv2")
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
func (c XChan) Close() {
|
| 76 |
+
close(c)
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
func (c XChan) Impl() string {
|
| 80 |
+
return "(<- operator)"
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
// indirect operations via select
|
| 84 |
+
type SChan chan int
|
| 85 |
+
|
| 86 |
+
func (c SChan) Send(x int) {
|
| 87 |
+
select {
|
| 88 |
+
case c <- x:
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
func (c SChan) Nbsend(x int) bool {
|
| 93 |
+
select {
|
| 94 |
+
default:
|
| 95 |
+
return false
|
| 96 |
+
case c <- x:
|
| 97 |
+
return true
|
| 98 |
+
}
|
| 99 |
+
panic("nbsend")
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
func (c SChan) Recv() int {
|
| 103 |
+
select {
|
| 104 |
+
case x := <-c:
|
| 105 |
+
return x
|
| 106 |
+
}
|
| 107 |
+
panic("recv")
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
func (c SChan) Nbrecv() (int, bool) {
|
| 111 |
+
select {
|
| 112 |
+
default:
|
| 113 |
+
return 0, false
|
| 114 |
+
case x := <-c:
|
| 115 |
+
return x, true
|
| 116 |
+
}
|
| 117 |
+
panic("nbrecv")
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
func (c SChan) Recv2() (int, bool) {
|
| 121 |
+
select {
|
| 122 |
+
case x, ok := <-c:
|
| 123 |
+
return x, ok
|
| 124 |
+
}
|
| 125 |
+
panic("recv")
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
func (c SChan) Nbrecv2() (int, bool, bool) {
|
| 129 |
+
select {
|
| 130 |
+
default:
|
| 131 |
+
return 0, false, false
|
| 132 |
+
case x, ok := <-c:
|
| 133 |
+
return x, ok, true
|
| 134 |
+
}
|
| 135 |
+
panic("nbrecv")
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
func (c SChan) Close() {
|
| 139 |
+
close(c)
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
func (c SChan) Impl() string {
|
| 143 |
+
return "(select)"
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// indirect operations via larger selects
|
| 147 |
+
var dummy = make(chan bool)
|
| 148 |
+
|
| 149 |
+
type SSChan chan int
|
| 150 |
+
|
| 151 |
+
func (c SSChan) Send(x int) {
|
| 152 |
+
select {
|
| 153 |
+
case c <- x:
|
| 154 |
+
case <-dummy:
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
func (c SSChan) Nbsend(x int) bool {
|
| 159 |
+
select {
|
| 160 |
+
default:
|
| 161 |
+
return false
|
| 162 |
+
case <-dummy:
|
| 163 |
+
case c <- x:
|
| 164 |
+
return true
|
| 165 |
+
}
|
| 166 |
+
panic("nbsend")
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
func (c SSChan) Recv() int {
|
| 170 |
+
select {
|
| 171 |
+
case <-dummy:
|
| 172 |
+
case x := <-c:
|
| 173 |
+
return x
|
| 174 |
+
}
|
| 175 |
+
panic("recv")
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
func (c SSChan) Nbrecv() (int, bool) {
|
| 179 |
+
select {
|
| 180 |
+
case <-dummy:
|
| 181 |
+
default:
|
| 182 |
+
return 0, false
|
| 183 |
+
case x := <-c:
|
| 184 |
+
return x, true
|
| 185 |
+
}
|
| 186 |
+
panic("nbrecv")
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
func (c SSChan) Recv2() (int, bool) {
|
| 190 |
+
select {
|
| 191 |
+
case <-dummy:
|
| 192 |
+
case x, ok := <-c:
|
| 193 |
+
return x, ok
|
| 194 |
+
}
|
| 195 |
+
panic("recv")
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
func (c SSChan) Nbrecv2() (int, bool, bool) {
|
| 199 |
+
select {
|
| 200 |
+
case <-dummy:
|
| 201 |
+
default:
|
| 202 |
+
return 0, false, false
|
| 203 |
+
case x, ok := <-c:
|
| 204 |
+
return x, ok, true
|
| 205 |
+
}
|
| 206 |
+
panic("nbrecv")
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
func (c SSChan) Close() {
|
| 210 |
+
close(c)
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
func (c SSChan) Impl() string {
|
| 214 |
+
return "(select)"
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
func shouldPanic(f func()) {
|
| 219 |
+
defer func() {
|
| 220 |
+
if recover() == nil {
|
| 221 |
+
panic("did not panic")
|
| 222 |
+
}
|
| 223 |
+
}()
|
| 224 |
+
f()
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
func test1(c Chan) {
|
| 228 |
+
for i := 0; i < 3; i++ {
|
| 229 |
+
// recv a close signal (a zero value)
|
| 230 |
+
if x := c.Recv(); x != 0 {
|
| 231 |
+
println("test1: recv on closed:", x, c.Impl())
|
| 232 |
+
failed = true
|
| 233 |
+
}
|
| 234 |
+
if x, ok := c.Recv2(); x != 0 || ok {
|
| 235 |
+
println("test1: recv2 on closed:", x, ok, c.Impl())
|
| 236 |
+
failed = true
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// should work with select: received a value without blocking, so selected == true.
|
| 240 |
+
x, selected := c.Nbrecv()
|
| 241 |
+
if x != 0 || !selected {
|
| 242 |
+
println("test1: recv on closed nb:", x, selected, c.Impl())
|
| 243 |
+
failed = true
|
| 244 |
+
}
|
| 245 |
+
x, ok, selected := c.Nbrecv2()
|
| 246 |
+
if x != 0 || ok || !selected {
|
| 247 |
+
println("test1: recv2 on closed nb:", x, ok, selected, c.Impl())
|
| 248 |
+
failed = true
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
// send should work with ,ok too: sent a value without blocking, so ok == true.
|
| 253 |
+
shouldPanic(func() { c.Nbsend(1) })
|
| 254 |
+
|
| 255 |
+
// the value should have been discarded.
|
| 256 |
+
if x := c.Recv(); x != 0 {
|
| 257 |
+
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
|
| 258 |
+
failed = true
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// similarly Send.
|
| 262 |
+
shouldPanic(func() { c.Send(2) })
|
| 263 |
+
if x := c.Recv(); x != 0 {
|
| 264 |
+
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
|
| 265 |
+
failed = true
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
func testasync1(c Chan) {
|
| 270 |
+
// should be able to get the last value via Recv
|
| 271 |
+
if x := c.Recv(); x != 1 {
|
| 272 |
+
println("testasync1: Recv did not get 1:", x, c.Impl())
|
| 273 |
+
failed = true
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
test1(c)
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
func testasync2(c Chan) {
|
| 280 |
+
// should be able to get the last value via Recv2
|
| 281 |
+
if x, ok := c.Recv2(); x != 1 || !ok {
|
| 282 |
+
println("testasync1: Recv did not get 1, true:", x, ok, c.Impl())
|
| 283 |
+
failed = true
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
test1(c)
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
func testasync3(c Chan) {
|
| 290 |
+
// should be able to get the last value via Nbrecv
|
| 291 |
+
if x, selected := c.Nbrecv(); x != 1 || !selected {
|
| 292 |
+
println("testasync2: Nbrecv did not get 1, true:", x, selected, c.Impl())
|
| 293 |
+
failed = true
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
test1(c)
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
func testasync4(c Chan) {
|
| 300 |
+
// should be able to get the last value via Nbrecv2
|
| 301 |
+
if x, ok, selected := c.Nbrecv2(); x != 1 || !ok || !selected {
|
| 302 |
+
println("testasync2: Nbrecv did not get 1, true, true:", x, ok, selected, c.Impl())
|
| 303 |
+
failed = true
|
| 304 |
+
}
|
| 305 |
+
test1(c)
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
func closedsync() chan int {
|
| 309 |
+
c := make(chan int)
|
| 310 |
+
close(c)
|
| 311 |
+
return c
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
func closedasync() chan int {
|
| 315 |
+
c := make(chan int, 2)
|
| 316 |
+
c <- 1
|
| 317 |
+
close(c)
|
| 318 |
+
return c
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
var mks = []func(chan int) Chan {
|
| 322 |
+
func(c chan int) Chan { return XChan(c) },
|
| 323 |
+
func(c chan int) Chan { return SChan(c) },
|
| 324 |
+
func(c chan int) Chan { return SSChan(c) },
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
var testcloseds = []func(Chan) {
|
| 328 |
+
testasync1,
|
| 329 |
+
testasync2,
|
| 330 |
+
testasync3,
|
| 331 |
+
testasync4,
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
func main() {
|
| 335 |
+
for _, mk := range mks {
|
| 336 |
+
test1(mk(closedsync()))
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
for _, testclosed := range testcloseds {
|
| 340 |
+
for _, mk := range mks {
|
| 341 |
+
testclosed(mk(closedasync()))
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
var ch chan int
|
| 346 |
+
shouldPanic(func() {
|
| 347 |
+
close(ch)
|
| 348 |
+
})
|
| 349 |
+
|
| 350 |
+
ch = make(chan int)
|
| 351 |
+
close(ch)
|
| 352 |
+
shouldPanic(func() {
|
| 353 |
+
close(ch)
|
| 354 |
+
})
|
| 355 |
+
|
| 356 |
+
if failed {
|
| 357 |
+
os.Exit(1)
|
| 358 |
+
}
|
| 359 |
+
}
|
platform/dbops/binaries/go/go/test/closure.go
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test the behavior of closures.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import "runtime"
|
| 12 |
+
|
| 13 |
+
var c = make(chan int)
|
| 14 |
+
|
| 15 |
+
func check(a []int) {
|
| 16 |
+
for i := 0; i < len(a); i++ {
|
| 17 |
+
n := <-c
|
| 18 |
+
if n != a[i] {
|
| 19 |
+
println("want", a[i], "got", n, "at", i)
|
| 20 |
+
panic("fail")
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
func f() {
|
| 26 |
+
var i, j int
|
| 27 |
+
|
| 28 |
+
i = 1
|
| 29 |
+
j = 2
|
| 30 |
+
f := func() {
|
| 31 |
+
c <- i
|
| 32 |
+
i = 4
|
| 33 |
+
g := func() {
|
| 34 |
+
c <- i
|
| 35 |
+
c <- j
|
| 36 |
+
}
|
| 37 |
+
g()
|
| 38 |
+
c <- i
|
| 39 |
+
}
|
| 40 |
+
j = 5
|
| 41 |
+
f()
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// Accumulator generator
|
| 45 |
+
func accum(n int) func(int) int {
|
| 46 |
+
return func(i int) int {
|
| 47 |
+
n += i
|
| 48 |
+
return n
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func g(a, b func(int) int) {
|
| 53 |
+
c <- a(2)
|
| 54 |
+
c <- b(3)
|
| 55 |
+
c <- a(4)
|
| 56 |
+
c <- b(5)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
func h() {
|
| 60 |
+
var x8 byte = 100
|
| 61 |
+
var x64 int64 = 200
|
| 62 |
+
|
| 63 |
+
c <- int(x8)
|
| 64 |
+
c <- int(x64)
|
| 65 |
+
f := func(z int) {
|
| 66 |
+
g := func() {
|
| 67 |
+
c <- int(x8)
|
| 68 |
+
c <- int(x64)
|
| 69 |
+
c <- z
|
| 70 |
+
}
|
| 71 |
+
g()
|
| 72 |
+
c <- int(x8)
|
| 73 |
+
c <- int(x64)
|
| 74 |
+
c <- int(z)
|
| 75 |
+
}
|
| 76 |
+
x8 = 101
|
| 77 |
+
x64 = 201
|
| 78 |
+
f(500)
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func newfunc() func(int) int { return func(x int) int { return x } }
|
| 82 |
+
|
| 83 |
+
func main() {
|
| 84 |
+
runtime.GOMAXPROCS(1)
|
| 85 |
+
var fail bool
|
| 86 |
+
|
| 87 |
+
go f()
|
| 88 |
+
check([]int{1, 4, 5, 4})
|
| 89 |
+
|
| 90 |
+
a := accum(0)
|
| 91 |
+
b := accum(1)
|
| 92 |
+
go g(a, b)
|
| 93 |
+
check([]int{2, 4, 6, 9})
|
| 94 |
+
|
| 95 |
+
go h()
|
| 96 |
+
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
|
| 97 |
+
|
| 98 |
+
memstats := new(runtime.MemStats)
|
| 99 |
+
runtime.ReadMemStats(memstats)
|
| 100 |
+
n0 := memstats.Mallocs
|
| 101 |
+
|
| 102 |
+
x, y := newfunc(), newfunc()
|
| 103 |
+
if x(1) != 1 || y(2) != 2 {
|
| 104 |
+
println("newfunc returned broken funcs")
|
| 105 |
+
fail = true
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
runtime.ReadMemStats(memstats)
|
| 109 |
+
if n0 != memstats.Mallocs {
|
| 110 |
+
println("newfunc allocated unexpectedly")
|
| 111 |
+
fail = true
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
ff(1)
|
| 115 |
+
|
| 116 |
+
if fail {
|
| 117 |
+
panic("fail")
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
func ff(x int) {
|
| 122 |
+
call(func() {
|
| 123 |
+
_ = x
|
| 124 |
+
})
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
func call(func()) {
|
| 128 |
+
}
|
platform/dbops/binaries/go/go/test/closure1.go
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
package main
|
| 8 |
+
|
| 9 |
+
func main() {
|
| 10 |
+
x := 0
|
| 11 |
+
func() {
|
| 12 |
+
x = 1
|
| 13 |
+
}()
|
| 14 |
+
func() {
|
| 15 |
+
if x != 1 {
|
| 16 |
+
panic("x != 1")
|
| 17 |
+
}
|
| 18 |
+
}()
|
| 19 |
+
}
|
platform/dbops/binaries/go/go/test/closure2.go
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Check that these do not use "by value" capturing,
|
| 8 |
+
// because changes are made to the value during the closure.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
var never bool
|
| 13 |
+
|
| 14 |
+
func main() {
|
| 15 |
+
{
|
| 16 |
+
type X struct {
|
| 17 |
+
v int
|
| 18 |
+
}
|
| 19 |
+
var x X
|
| 20 |
+
func() {
|
| 21 |
+
x.v++
|
| 22 |
+
}()
|
| 23 |
+
if x.v != 1 {
|
| 24 |
+
panic("x.v != 1")
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
type Y struct {
|
| 28 |
+
X
|
| 29 |
+
}
|
| 30 |
+
var y Y
|
| 31 |
+
func() {
|
| 32 |
+
y.v = 1
|
| 33 |
+
}()
|
| 34 |
+
if y.v != 1 {
|
| 35 |
+
panic("y.v != 1")
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
{
|
| 40 |
+
type Z struct {
|
| 41 |
+
a [3]byte
|
| 42 |
+
}
|
| 43 |
+
var z Z
|
| 44 |
+
func() {
|
| 45 |
+
i := 0
|
| 46 |
+
for z.a[1] = 1; i < 10; i++ {
|
| 47 |
+
}
|
| 48 |
+
}()
|
| 49 |
+
if z.a[1] != 1 {
|
| 50 |
+
panic("z.a[1] != 1")
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
{
|
| 55 |
+
w := 0
|
| 56 |
+
tmp := 0
|
| 57 |
+
f := func() {
|
| 58 |
+
if w != 1 {
|
| 59 |
+
panic("w != 1")
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
func() {
|
| 63 |
+
tmp = w // force capture of w, but do not write to it yet
|
| 64 |
+
_ = tmp
|
| 65 |
+
func() {
|
| 66 |
+
func() {
|
| 67 |
+
w++ // write in a nested closure
|
| 68 |
+
}()
|
| 69 |
+
}()
|
| 70 |
+
}()
|
| 71 |
+
f()
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
{
|
| 75 |
+
var g func() int
|
| 76 |
+
var i int
|
| 77 |
+
for i = range [2]int{} {
|
| 78 |
+
if i == 0 {
|
| 79 |
+
g = func() int {
|
| 80 |
+
return i // test that we capture by ref here, i is mutated on every interaction
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
if g() != 1 {
|
| 85 |
+
panic("g() != 1")
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
{
|
| 90 |
+
var g func() int
|
| 91 |
+
q := 0
|
| 92 |
+
for range [2]int{} {
|
| 93 |
+
q++
|
| 94 |
+
g = func() int {
|
| 95 |
+
return q // test that we capture by ref here
|
| 96 |
+
// q++ must on a different decldepth than q declaration
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
if g() != 2 {
|
| 100 |
+
panic("g() != 2")
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
{
|
| 105 |
+
var g func() int
|
| 106 |
+
var a [2]int
|
| 107 |
+
q := 0
|
| 108 |
+
for a[func() int {
|
| 109 |
+
q++
|
| 110 |
+
return 0
|
| 111 |
+
}()] = range [2]int{} {
|
| 112 |
+
g = func() int {
|
| 113 |
+
return q // test that we capture by ref here
|
| 114 |
+
// q++ must on a different decldepth than q declaration
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
if g() != 2 {
|
| 118 |
+
panic("g() != 2")
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
{
|
| 123 |
+
var g func() int
|
| 124 |
+
q := 0
|
| 125 |
+
q, g = 1, func() int { return q }
|
| 126 |
+
if never {
|
| 127 |
+
g = func() int { return 2 }
|
| 128 |
+
}
|
| 129 |
+
if g() != 1 {
|
| 130 |
+
panic("g() != 1")
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
}
|
platform/dbops/binaries/go/go/test/closure3.go
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheckandrundir -0 -m -d=inlfuncswithclosures=1
|
| 2 |
+
|
| 3 |
+
//go:build !goexperiment.newinliner
|
| 4 |
+
|
| 5 |
+
// Copyright 2017 The Go Authors. All rights reserved.
|
| 6 |
+
// Use of this source code is governed by a BSD-style
|
| 7 |
+
// license that can be found in the LICENSE file.
|
| 8 |
+
|
| 9 |
+
// Check correctness of various closure corner cases
|
| 10 |
+
// that are expected to be inlined
|
| 11 |
+
|
| 12 |
+
package ignored
|
platform/dbops/binaries/go/go/test/closure4.go
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2018 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Check that calling a nil func causes a proper panic.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
func main() {
|
| 12 |
+
defer func() {
|
| 13 |
+
err := recover()
|
| 14 |
+
if err == nil {
|
| 15 |
+
panic("panic expected")
|
| 16 |
+
}
|
| 17 |
+
}()
|
| 18 |
+
|
| 19 |
+
var f func()
|
| 20 |
+
f()
|
| 21 |
+
}
|
platform/dbops/binaries/go/go/test/closure5.go
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// compiledir
|
| 2 |
+
|
| 3 |
+
// Copyright 2021 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Check correctness of various closure corner cases
|
| 8 |
+
// that are expected to be inlined
|
| 9 |
+
|
| 10 |
+
package ignored
|
platform/dbops/binaries/go/go/test/closure6.go
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// compile
|
| 2 |
+
|
| 3 |
+
// Copyright 2020 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
package p
|
| 8 |
+
|
| 9 |
+
type Float64Slice []float64
|
| 10 |
+
|
| 11 |
+
func (a Float64Slice) Search1(x float64) int {
|
| 12 |
+
f := func(q int) bool { return a[q] >= x }
|
| 13 |
+
i := 0
|
| 14 |
+
if !f(3) {
|
| 15 |
+
i = 5
|
| 16 |
+
}
|
| 17 |
+
return i
|
| 18 |
+
}
|
platform/dbops/binaries/go/go/test/closure7.go
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2020 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
package main
|
| 8 |
+
|
| 9 |
+
func g(f func()) {
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Must have exportable name
|
| 13 |
+
func F() {
|
| 14 |
+
g(func() {
|
| 15 |
+
ch := make(chan int)
|
| 16 |
+
for {
|
| 17 |
+
select {
|
| 18 |
+
case <-ch:
|
| 19 |
+
return
|
| 20 |
+
default:
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
})
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
func main() {
|
| 27 |
+
F()
|
| 28 |
+
}
|
platform/dbops/binaries/go/go/test/cmp.go
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test equality and inequality operations.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"os"
|
| 13 |
+
"unsafe"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
var global bool
|
| 17 |
+
|
| 18 |
+
func use(b bool) { global = b }
|
| 19 |
+
|
| 20 |
+
func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
|
| 21 |
+
|
| 22 |
+
func isfalse(b bool) {
|
| 23 |
+
if b {
|
| 24 |
+
// stack will explain where
|
| 25 |
+
panic("wanted false, got true")
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
func istrue(b bool) {
|
| 30 |
+
if !b {
|
| 31 |
+
// stack will explain where
|
| 32 |
+
panic("wanted true, got false")
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type T *int
|
| 37 |
+
|
| 38 |
+
type X int
|
| 39 |
+
|
| 40 |
+
func (X) x() {}
|
| 41 |
+
|
| 42 |
+
func main() {
|
| 43 |
+
var a []int
|
| 44 |
+
var b map[string]int
|
| 45 |
+
|
| 46 |
+
var c string = "hello"
|
| 47 |
+
var d string = "hel" // try to get different pointer
|
| 48 |
+
d = d + "lo"
|
| 49 |
+
|
| 50 |
+
// go.tools/ssa/interp can't handle unsafe.Pointer.
|
| 51 |
+
if os.Getenv("GOSSAINTERP") == "" {
|
| 52 |
+
if stringptr(c) == stringptr(d) {
|
| 53 |
+
panic("compiler too smart -- got same string")
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
var e = make(chan int)
|
| 58 |
+
|
| 59 |
+
var ia interface{} = a
|
| 60 |
+
var ib interface{} = b
|
| 61 |
+
var ic interface{} = c
|
| 62 |
+
var id interface{} = d
|
| 63 |
+
var ie interface{} = e
|
| 64 |
+
|
| 65 |
+
// these comparisons are okay because
|
| 66 |
+
// string compare is okay and the others
|
| 67 |
+
// are comparisons where the types differ.
|
| 68 |
+
isfalse(ia == ib)
|
| 69 |
+
isfalse(ia == ic)
|
| 70 |
+
isfalse(ia == id)
|
| 71 |
+
isfalse(ib == ic)
|
| 72 |
+
isfalse(ib == id)
|
| 73 |
+
istrue(ic == id)
|
| 74 |
+
istrue(ie == ie)
|
| 75 |
+
|
| 76 |
+
istrue(ia != ib)
|
| 77 |
+
istrue(ia != ic)
|
| 78 |
+
istrue(ia != id)
|
| 79 |
+
istrue(ib != ic)
|
| 80 |
+
istrue(ib != id)
|
| 81 |
+
isfalse(ic != id)
|
| 82 |
+
isfalse(ie != ie)
|
| 83 |
+
|
| 84 |
+
// these are not okay, because there is no comparison on slices or maps.
|
| 85 |
+
//isfalse(a == ib)
|
| 86 |
+
//isfalse(a == ic)
|
| 87 |
+
//isfalse(a == id)
|
| 88 |
+
//isfalse(b == ic)
|
| 89 |
+
//isfalse(b == id)
|
| 90 |
+
|
| 91 |
+
istrue(c == id)
|
| 92 |
+
istrue(e == ie)
|
| 93 |
+
|
| 94 |
+
//isfalse(ia == b)
|
| 95 |
+
isfalse(ia == c)
|
| 96 |
+
isfalse(ia == d)
|
| 97 |
+
isfalse(ib == c)
|
| 98 |
+
isfalse(ib == d)
|
| 99 |
+
istrue(ic == d)
|
| 100 |
+
istrue(ie == e)
|
| 101 |
+
|
| 102 |
+
//istrue(a != ib)
|
| 103 |
+
//istrue(a != ic)
|
| 104 |
+
//istrue(a != id)
|
| 105 |
+
//istrue(b != ic)
|
| 106 |
+
//istrue(b != id)
|
| 107 |
+
isfalse(c != id)
|
| 108 |
+
isfalse(e != ie)
|
| 109 |
+
|
| 110 |
+
//istrue(ia != b)
|
| 111 |
+
istrue(ia != c)
|
| 112 |
+
istrue(ia != d)
|
| 113 |
+
istrue(ib != c)
|
| 114 |
+
istrue(ib != d)
|
| 115 |
+
isfalse(ic != d)
|
| 116 |
+
isfalse(ie != e)
|
| 117 |
+
|
| 118 |
+
// gc used to let this go through as true.
|
| 119 |
+
var g uint64 = 123
|
| 120 |
+
var h int64 = 123
|
| 121 |
+
var ig interface{} = g
|
| 122 |
+
var ih interface{} = h
|
| 123 |
+
isfalse(ig == ih)
|
| 124 |
+
istrue(ig != ih)
|
| 125 |
+
|
| 126 |
+
// map of interface should use == on interface values,
|
| 127 |
+
// not memory.
|
| 128 |
+
var m = make(map[interface{}]int)
|
| 129 |
+
m[ic] = 1
|
| 130 |
+
m[id] = 2
|
| 131 |
+
if m[c] != 2 {
|
| 132 |
+
println("m[c] = ", m[c])
|
| 133 |
+
panic("bad m[c]")
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// interface comparisons (issue 7207)
|
| 137 |
+
{
|
| 138 |
+
type I1 interface {
|
| 139 |
+
x()
|
| 140 |
+
}
|
| 141 |
+
type I2 interface {
|
| 142 |
+
x()
|
| 143 |
+
}
|
| 144 |
+
a1 := I1(X(0))
|
| 145 |
+
b1 := I1(X(1))
|
| 146 |
+
a2 := I2(X(0))
|
| 147 |
+
b2 := I2(X(1))
|
| 148 |
+
a3 := I1(a2)
|
| 149 |
+
a4 := I2(a1)
|
| 150 |
+
var e interface{} = X(0)
|
| 151 |
+
a5 := e.(I1)
|
| 152 |
+
a6 := e.(I2)
|
| 153 |
+
isfalse(a1 == b1)
|
| 154 |
+
isfalse(a1 == b2)
|
| 155 |
+
isfalse(a2 == b1)
|
| 156 |
+
isfalse(a2 == b2)
|
| 157 |
+
istrue(a1 == a2)
|
| 158 |
+
istrue(a1 == a3)
|
| 159 |
+
istrue(a1 == a4)
|
| 160 |
+
istrue(a1 == a5)
|
| 161 |
+
istrue(a1 == a6)
|
| 162 |
+
istrue(a2 == a3)
|
| 163 |
+
istrue(a2 == a4)
|
| 164 |
+
istrue(a2 == a5)
|
| 165 |
+
istrue(a2 == a6)
|
| 166 |
+
istrue(a3 == a4)
|
| 167 |
+
istrue(a3 == a5)
|
| 168 |
+
istrue(a3 == a6)
|
| 169 |
+
istrue(a4 == a5)
|
| 170 |
+
istrue(a4 == a6)
|
| 171 |
+
istrue(a5 == a6)
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// non-interface comparisons
|
| 175 |
+
{
|
| 176 |
+
c := make(chan int)
|
| 177 |
+
c1 := (<-chan int)(c)
|
| 178 |
+
c2 := (chan<- int)(c)
|
| 179 |
+
istrue(c == c1)
|
| 180 |
+
istrue(c == c2)
|
| 181 |
+
istrue(c1 == c)
|
| 182 |
+
istrue(c2 == c)
|
| 183 |
+
|
| 184 |
+
isfalse(c != c1)
|
| 185 |
+
isfalse(c != c2)
|
| 186 |
+
isfalse(c1 != c)
|
| 187 |
+
isfalse(c2 != c)
|
| 188 |
+
|
| 189 |
+
d := make(chan int)
|
| 190 |
+
isfalse(c == d)
|
| 191 |
+
isfalse(d == c)
|
| 192 |
+
isfalse(d == c1)
|
| 193 |
+
isfalse(d == c2)
|
| 194 |
+
isfalse(c1 == d)
|
| 195 |
+
isfalse(c2 == d)
|
| 196 |
+
|
| 197 |
+
istrue(c != d)
|
| 198 |
+
istrue(d != c)
|
| 199 |
+
istrue(d != c1)
|
| 200 |
+
istrue(d != c2)
|
| 201 |
+
istrue(c1 != d)
|
| 202 |
+
istrue(c2 != d)
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// named types vs not
|
| 206 |
+
{
|
| 207 |
+
var x = new(int)
|
| 208 |
+
var y T
|
| 209 |
+
var z T = x
|
| 210 |
+
|
| 211 |
+
isfalse(x == y)
|
| 212 |
+
istrue(x == z)
|
| 213 |
+
isfalse(y == z)
|
| 214 |
+
|
| 215 |
+
isfalse(y == x)
|
| 216 |
+
istrue(z == x)
|
| 217 |
+
isfalse(z == y)
|
| 218 |
+
|
| 219 |
+
istrue(x != y)
|
| 220 |
+
isfalse(x != z)
|
| 221 |
+
istrue(y != z)
|
| 222 |
+
|
| 223 |
+
istrue(y != x)
|
| 224 |
+
isfalse(z != x)
|
| 225 |
+
istrue(z != y)
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// structs
|
| 229 |
+
{
|
| 230 |
+
var x = struct {
|
| 231 |
+
x int
|
| 232 |
+
y string
|
| 233 |
+
}{1, "hi"}
|
| 234 |
+
var y = struct {
|
| 235 |
+
x int
|
| 236 |
+
y string
|
| 237 |
+
}{2, "bye"}
|
| 238 |
+
var z = struct {
|
| 239 |
+
x int
|
| 240 |
+
y string
|
| 241 |
+
}{1, "hi"}
|
| 242 |
+
|
| 243 |
+
isfalse(x == y)
|
| 244 |
+
isfalse(y == x)
|
| 245 |
+
isfalse(y == z)
|
| 246 |
+
isfalse(z == y)
|
| 247 |
+
istrue(x == z)
|
| 248 |
+
istrue(z == x)
|
| 249 |
+
|
| 250 |
+
istrue(x != y)
|
| 251 |
+
istrue(y != x)
|
| 252 |
+
istrue(y != z)
|
| 253 |
+
istrue(z != y)
|
| 254 |
+
isfalse(x != z)
|
| 255 |
+
isfalse(z != x)
|
| 256 |
+
|
| 257 |
+
var m = make(map[struct {
|
| 258 |
+
x int
|
| 259 |
+
y string
|
| 260 |
+
}]int)
|
| 261 |
+
m[x] = 10
|
| 262 |
+
m[y] = 20
|
| 263 |
+
m[z] = 30
|
| 264 |
+
istrue(m[x] == 30)
|
| 265 |
+
istrue(m[y] == 20)
|
| 266 |
+
istrue(m[z] == 30)
|
| 267 |
+
istrue(m[x] != 10)
|
| 268 |
+
isfalse(m[x] != 30)
|
| 269 |
+
isfalse(m[y] != 20)
|
| 270 |
+
isfalse(m[z] != 30)
|
| 271 |
+
isfalse(m[x] == 10)
|
| 272 |
+
|
| 273 |
+
var m1 = make(map[struct {
|
| 274 |
+
x int
|
| 275 |
+
y string
|
| 276 |
+
}]struct {
|
| 277 |
+
x int
|
| 278 |
+
y string
|
| 279 |
+
})
|
| 280 |
+
m1[x] = x
|
| 281 |
+
m1[y] = y
|
| 282 |
+
m1[z] = z
|
| 283 |
+
istrue(m1[x] == z)
|
| 284 |
+
istrue(m1[y] == y)
|
| 285 |
+
istrue(m1[z] == z)
|
| 286 |
+
istrue(m1[x] == x)
|
| 287 |
+
isfalse(m1[x] != z)
|
| 288 |
+
isfalse(m1[y] != y)
|
| 289 |
+
isfalse(m1[z] != z)
|
| 290 |
+
isfalse(m1[x] != x)
|
| 291 |
+
|
| 292 |
+
var ix, iy, iz interface{} = x, y, z
|
| 293 |
+
|
| 294 |
+
isfalse(ix == iy)
|
| 295 |
+
isfalse(iy == ix)
|
| 296 |
+
isfalse(iy == iz)
|
| 297 |
+
isfalse(iz == iy)
|
| 298 |
+
istrue(ix == iz)
|
| 299 |
+
istrue(iz == ix)
|
| 300 |
+
|
| 301 |
+
isfalse(x == iy)
|
| 302 |
+
isfalse(y == ix)
|
| 303 |
+
isfalse(y == iz)
|
| 304 |
+
isfalse(z == iy)
|
| 305 |
+
istrue(x == iz)
|
| 306 |
+
istrue(z == ix)
|
| 307 |
+
|
| 308 |
+
isfalse(ix == y)
|
| 309 |
+
isfalse(iy == x)
|
| 310 |
+
isfalse(iy == z)
|
| 311 |
+
isfalse(iz == y)
|
| 312 |
+
istrue(ix == z)
|
| 313 |
+
istrue(iz == x)
|
| 314 |
+
|
| 315 |
+
istrue(ix != iy)
|
| 316 |
+
istrue(iy != ix)
|
| 317 |
+
istrue(iy != iz)
|
| 318 |
+
istrue(iz != iy)
|
| 319 |
+
isfalse(ix != iz)
|
| 320 |
+
isfalse(iz != ix)
|
| 321 |
+
|
| 322 |
+
istrue(x != iy)
|
| 323 |
+
istrue(y != ix)
|
| 324 |
+
istrue(y != iz)
|
| 325 |
+
istrue(z != iy)
|
| 326 |
+
isfalse(x != iz)
|
| 327 |
+
isfalse(z != ix)
|
| 328 |
+
|
| 329 |
+
istrue(ix != y)
|
| 330 |
+
istrue(iy != x)
|
| 331 |
+
istrue(iy != z)
|
| 332 |
+
istrue(iz != y)
|
| 333 |
+
isfalse(ix != z)
|
| 334 |
+
isfalse(iz != x)
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// structs with _ fields
|
| 338 |
+
{
|
| 339 |
+
var x = struct {
|
| 340 |
+
x int
|
| 341 |
+
_ string
|
| 342 |
+
y float64
|
| 343 |
+
_ float64
|
| 344 |
+
z int
|
| 345 |
+
}{
|
| 346 |
+
x: 1, y: 2, z: 3,
|
| 347 |
+
}
|
| 348 |
+
var ix interface{} = x
|
| 349 |
+
|
| 350 |
+
istrue(x == x)
|
| 351 |
+
istrue(x == ix)
|
| 352 |
+
istrue(ix == x)
|
| 353 |
+
istrue(ix == ix)
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
// arrays
|
| 357 |
+
{
|
| 358 |
+
var x = [2]string{"1", "hi"}
|
| 359 |
+
var y = [2]string{"2", "bye"}
|
| 360 |
+
var z = [2]string{"1", "hi"}
|
| 361 |
+
|
| 362 |
+
isfalse(x == y)
|
| 363 |
+
isfalse(y == x)
|
| 364 |
+
isfalse(y == z)
|
| 365 |
+
isfalse(z == y)
|
| 366 |
+
istrue(x == z)
|
| 367 |
+
istrue(z == x)
|
| 368 |
+
|
| 369 |
+
istrue(x != y)
|
| 370 |
+
istrue(y != x)
|
| 371 |
+
istrue(y != z)
|
| 372 |
+
istrue(z != y)
|
| 373 |
+
isfalse(x != z)
|
| 374 |
+
isfalse(z != x)
|
| 375 |
+
|
| 376 |
+
var m = make(map[[2]string]int)
|
| 377 |
+
m[x] = 10
|
| 378 |
+
m[y] = 20
|
| 379 |
+
m[z] = 30
|
| 380 |
+
istrue(m[x] == 30)
|
| 381 |
+
istrue(m[y] == 20)
|
| 382 |
+
istrue(m[z] == 30)
|
| 383 |
+
isfalse(m[x] != 30)
|
| 384 |
+
isfalse(m[y] != 20)
|
| 385 |
+
isfalse(m[z] != 30)
|
| 386 |
+
|
| 387 |
+
var ix, iy, iz interface{} = x, y, z
|
| 388 |
+
|
| 389 |
+
isfalse(ix == iy)
|
| 390 |
+
isfalse(iy == ix)
|
| 391 |
+
isfalse(iy == iz)
|
| 392 |
+
isfalse(iz == iy)
|
| 393 |
+
istrue(ix == iz)
|
| 394 |
+
istrue(iz == ix)
|
| 395 |
+
|
| 396 |
+
isfalse(x == iy)
|
| 397 |
+
isfalse(y == ix)
|
| 398 |
+
isfalse(y == iz)
|
| 399 |
+
isfalse(z == iy)
|
| 400 |
+
istrue(x == iz)
|
| 401 |
+
istrue(z == ix)
|
| 402 |
+
|
| 403 |
+
isfalse(ix == y)
|
| 404 |
+
isfalse(iy == x)
|
| 405 |
+
isfalse(iy == z)
|
| 406 |
+
isfalse(iz == y)
|
| 407 |
+
istrue(ix == z)
|
| 408 |
+
istrue(iz == x)
|
| 409 |
+
|
| 410 |
+
istrue(ix != iy)
|
| 411 |
+
istrue(iy != ix)
|
| 412 |
+
istrue(iy != iz)
|
| 413 |
+
istrue(iz != iy)
|
| 414 |
+
isfalse(ix != iz)
|
| 415 |
+
isfalse(iz != ix)
|
| 416 |
+
|
| 417 |
+
istrue(x != iy)
|
| 418 |
+
istrue(y != ix)
|
| 419 |
+
istrue(y != iz)
|
| 420 |
+
istrue(z != iy)
|
| 421 |
+
isfalse(x != iz)
|
| 422 |
+
isfalse(z != ix)
|
| 423 |
+
|
| 424 |
+
istrue(ix != y)
|
| 425 |
+
istrue(iy != x)
|
| 426 |
+
istrue(iy != z)
|
| 427 |
+
istrue(iz != y)
|
| 428 |
+
isfalse(ix != z)
|
| 429 |
+
isfalse(iz != x)
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
// named booleans
|
| 433 |
+
{
|
| 434 |
+
type mybool bool
|
| 435 |
+
var b mybool
|
| 436 |
+
|
| 437 |
+
type T struct{ data [20]byte }
|
| 438 |
+
var x, y T
|
| 439 |
+
b = x == y
|
| 440 |
+
istrue(x == y)
|
| 441 |
+
istrue(bool(b))
|
| 442 |
+
|
| 443 |
+
m := make(map[string][10]interface{})
|
| 444 |
+
b = m["x"] == m["y"]
|
| 445 |
+
istrue(m["x"] == m["y"])
|
| 446 |
+
istrue(bool(b))
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
shouldPanic(p1)
|
| 450 |
+
shouldPanic(p2)
|
| 451 |
+
shouldPanic(p3)
|
| 452 |
+
shouldPanic(p4)
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
func p1() {
|
| 456 |
+
var a []int
|
| 457 |
+
var ia interface{} = a
|
| 458 |
+
use(ia == ia)
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
func p2() {
|
| 462 |
+
var b []int
|
| 463 |
+
var ib interface{} = b
|
| 464 |
+
use(ib == ib)
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
func p3() {
|
| 468 |
+
var a []int
|
| 469 |
+
var ia interface{} = a
|
| 470 |
+
var m = make(map[interface{}]int)
|
| 471 |
+
m[ia] = 1
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
func p4() {
|
| 475 |
+
var b []int
|
| 476 |
+
var ib interface{} = b
|
| 477 |
+
var m = make(map[interface{}]int)
|
| 478 |
+
m[ib] = 1
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
func shouldPanic(f func()) {
|
| 482 |
+
defer func() {
|
| 483 |
+
if recover() == nil {
|
| 484 |
+
panic("function should panic")
|
| 485 |
+
}
|
| 486 |
+
}()
|
| 487 |
+
f()
|
| 488 |
+
}
|
platform/dbops/binaries/go/go/test/cmp6.go
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that incorrect comparisons are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
func use(bool) {}
|
| 13 |
+
|
| 14 |
+
type T1 *int
|
| 15 |
+
type T2 *int
|
| 16 |
+
|
| 17 |
+
type T3 struct{ z []int }
|
| 18 |
+
|
| 19 |
+
var t3 T3
|
| 20 |
+
|
| 21 |
+
type T4 struct {
|
| 22 |
+
_ []int
|
| 23 |
+
a float64
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
var t4 T4
|
| 27 |
+
|
| 28 |
+
func main() {
|
| 29 |
+
// Arguments to comparison must be
|
| 30 |
+
// assignable one to the other (or vice versa)
|
| 31 |
+
// so chan int can be compared against
|
| 32 |
+
// directional channels but channel of different
|
| 33 |
+
// direction cannot be compared against each other.
|
| 34 |
+
var c1 chan<- int
|
| 35 |
+
var c2 <-chan int
|
| 36 |
+
var c3 chan int
|
| 37 |
+
|
| 38 |
+
use(c1 == c2) // ERROR "invalid operation|incompatible"
|
| 39 |
+
use(c2 == c1) // ERROR "invalid operation|incompatible"
|
| 40 |
+
use(c1 == c3)
|
| 41 |
+
use(c2 == c2)
|
| 42 |
+
use(c3 == c1)
|
| 43 |
+
use(c3 == c2)
|
| 44 |
+
|
| 45 |
+
// Same applies to named types.
|
| 46 |
+
var p1 T1
|
| 47 |
+
var p2 T2
|
| 48 |
+
var p3 *int
|
| 49 |
+
|
| 50 |
+
use(p1 == p2) // ERROR "invalid operation|incompatible"
|
| 51 |
+
use(p2 == p1) // ERROR "invalid operation|incompatible"
|
| 52 |
+
use(p1 == p3)
|
| 53 |
+
use(p2 == p2)
|
| 54 |
+
use(p3 == p1)
|
| 55 |
+
use(p3 == p2)
|
| 56 |
+
|
| 57 |
+
// Arrays are comparable if and only if their element type is comparable.
|
| 58 |
+
var a1 [1]int
|
| 59 |
+
var a2 [1]func()
|
| 60 |
+
var a3 [0]func()
|
| 61 |
+
use(a1 == a1)
|
| 62 |
+
use(a2 == a2) // ERROR "invalid operation|invalid comparison"
|
| 63 |
+
use(a3 == a3) // ERROR "invalid operation|invalid comparison"
|
| 64 |
+
|
| 65 |
+
// Comparison of structs should have a good message
|
| 66 |
+
use(t3 == t3) // ERROR "struct|expected|cannot compare"
|
| 67 |
+
use(t4 == t4) // ERROR "cannot be compared|non-comparable|cannot compare"
|
| 68 |
+
|
| 69 |
+
// Slices, functions, and maps too.
|
| 70 |
+
var x []int
|
| 71 |
+
var f func()
|
| 72 |
+
var m map[int]int
|
| 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"
|
| 76 |
+
|
| 77 |
+
// Comparison with interface that cannot return true
|
| 78 |
+
// (would panic).
|
| 79 |
+
var i interface{}
|
| 80 |
+
use(i == x) // ERROR "invalid operation"
|
| 81 |
+
use(x == i) // ERROR "invalid operation"
|
| 82 |
+
use(i == f) // ERROR "invalid operation"
|
| 83 |
+
use(f == i) // ERROR "invalid operation"
|
| 84 |
+
use(i == m) // ERROR "invalid operation"
|
| 85 |
+
use(m == i) // ERROR "invalid operation"
|
| 86 |
+
}
|
platform/dbops/binaries/go/go/test/cmplx.go
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that incorrect invocations of the complex predeclared function are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
type (
|
| 13 |
+
Float32 float32
|
| 14 |
+
Float64 float64
|
| 15 |
+
Complex64 complex64
|
| 16 |
+
Complex128 complex128
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
var (
|
| 20 |
+
f32 float32
|
| 21 |
+
f64 float64
|
| 22 |
+
F32 Float32
|
| 23 |
+
F64 Float64
|
| 24 |
+
|
| 25 |
+
c64 complex64
|
| 26 |
+
c128 complex128
|
| 27 |
+
C64 Complex64
|
| 28 |
+
C128 Complex128
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
func F1() int {
|
| 32 |
+
return 1
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
func F3() (int, int, int) {
|
| 36 |
+
return 1, 2, 3
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func main() {
|
| 40 |
+
// ok
|
| 41 |
+
c64 = complex(f32, f32)
|
| 42 |
+
c128 = complex(f64, f64)
|
| 43 |
+
|
| 44 |
+
_ = complex128(0) // ok
|
| 45 |
+
_ = complex(f32, f64) // ERROR "complex"
|
| 46 |
+
_ = complex(f64, f32) // ERROR "complex"
|
| 47 |
+
_ = complex(f32, F32) // ERROR "complex"
|
| 48 |
+
_ = complex(F32, f32) // ERROR "complex"
|
| 49 |
+
_ = complex(f64, F64) // ERROR "complex"
|
| 50 |
+
_ = complex(F64, f64) // ERROR "complex"
|
| 51 |
+
|
| 52 |
+
_ = complex(F1()) // ERROR "not enough arguments"
|
| 53 |
+
_ = complex(F3()) // ERROR "too many arguments"
|
| 54 |
+
|
| 55 |
+
_ = complex() // ERROR "not enough arguments"
|
| 56 |
+
|
| 57 |
+
c128 = complex(f32, f32) // ERROR "cannot use"
|
| 58 |
+
c64 = complex(f64, f64) // ERROR "cannot use"
|
| 59 |
+
|
| 60 |
+
c64 = complex(1.0, 2.0) // ok, constant is untyped
|
| 61 |
+
c128 = complex(1.0, 2.0)
|
| 62 |
+
C64 = complex(1.0, 2.0)
|
| 63 |
+
C128 = complex(1.0, 2.0)
|
| 64 |
+
|
| 65 |
+
C64 = complex(f32, f32) // ERROR "cannot use"
|
| 66 |
+
C128 = complex(f64, f64) // ERROR "cannot use"
|
| 67 |
+
|
| 68 |
+
}
|
platform/dbops/binaries/go/go/test/cmplxdivide.c
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 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 |
+
// This C program generates the file cmplxdivide1.go. It uses the
|
| 6 |
+
// output of the operations by C99 as the reference to check
|
| 7 |
+
// the implementation of complex numbers in Go.
|
| 8 |
+
// The generated file, cmplxdivide1.go, is compiled along
|
| 9 |
+
// with the driver cmplxdivide.go (the names are confusing
|
| 10 |
+
// and unimaginative) to run the actual test. This is done by
|
| 11 |
+
// the usual test runner.
|
| 12 |
+
//
|
| 13 |
+
// The file cmplxdivide1.go is checked in to the repository, but
|
| 14 |
+
// if it needs to be regenerated, compile and run this C program
|
| 15 |
+
// like this:
|
| 16 |
+
// gcc '-std=c99' cmplxdivide.c && a.out >cmplxdivide1.go
|
| 17 |
+
|
| 18 |
+
#include <complex.h>
|
| 19 |
+
#include <math.h>
|
| 20 |
+
#include <stdio.h>
|
| 21 |
+
#include <string.h>
|
| 22 |
+
|
| 23 |
+
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
| 24 |
+
|
| 25 |
+
double f[] = {
|
| 26 |
+
0.0,
|
| 27 |
+
-0.0,
|
| 28 |
+
1.0,
|
| 29 |
+
-1.0,
|
| 30 |
+
2.0,
|
| 31 |
+
NAN,
|
| 32 |
+
INFINITY,
|
| 33 |
+
-INFINITY,
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
char* fmt(double g) {
|
| 37 |
+
static char buf[10][30];
|
| 38 |
+
static int n;
|
| 39 |
+
char *p;
|
| 40 |
+
|
| 41 |
+
p = buf[n++];
|
| 42 |
+
if(n == 10) {
|
| 43 |
+
n = 0;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
sprintf(p, "%g", g);
|
| 47 |
+
|
| 48 |
+
if(strcmp(p, "0") == 0) {
|
| 49 |
+
strcpy(p, "zero");
|
| 50 |
+
return p;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if(strcmp(p, "-0") == 0) {
|
| 54 |
+
strcpy(p, "-zero");
|
| 55 |
+
return p;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return p;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
int main(void) {
|
| 62 |
+
int i, j, k, l;
|
| 63 |
+
double complex n, d, q;
|
| 64 |
+
|
| 65 |
+
printf("// skip\n");
|
| 66 |
+
printf("// # generated by cmplxdivide.c\n");
|
| 67 |
+
printf("\n");
|
| 68 |
+
printf("package main\n");
|
| 69 |
+
printf("\n");
|
| 70 |
+
printf("import \"math\"\n");
|
| 71 |
+
printf("\n");
|
| 72 |
+
printf("var (\n");
|
| 73 |
+
printf("\tnan = math.NaN()\n");
|
| 74 |
+
printf("\tinf = math.Inf(1)\n");
|
| 75 |
+
printf("\tzero = 0.0\n");
|
| 76 |
+
printf(")\n");
|
| 77 |
+
printf("\n");
|
| 78 |
+
printf("var tests = []struct {\n");
|
| 79 |
+
printf("\tf, g complex128\n");
|
| 80 |
+
printf("\tout complex128\n");
|
| 81 |
+
printf("}{\n");
|
| 82 |
+
|
| 83 |
+
for(i=0; i<nelem(f); i++)
|
| 84 |
+
for(j=0; j<nelem(f); j++)
|
| 85 |
+
for(k=0; k<nelem(f); k++)
|
| 86 |
+
for(l=0; l<nelem(f); l++) {
|
| 87 |
+
n = f[i] + f[j]*I;
|
| 88 |
+
d = f[k] + f[l]*I;
|
| 89 |
+
q = n/d;
|
| 90 |
+
|
| 91 |
+
printf("\t{complex(%s, %s), complex(%s, %s), complex(%s, %s)},\n",
|
| 92 |
+
fmt(creal(n)), fmt(cimag(n)),
|
| 93 |
+
fmt(creal(d)), fmt(cimag(d)),
|
| 94 |
+
fmt(creal(q)), fmt(cimag(q)));
|
| 95 |
+
}
|
| 96 |
+
printf("}\n");
|
| 97 |
+
return 0;
|
| 98 |
+
}
|
platform/dbops/binaries/go/go/test/cmplxdivide.go
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run cmplxdivide1.go
|
| 2 |
+
|
| 3 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Driver for complex division table defined in cmplxdivide1.go
|
| 8 |
+
// For details, see the comment at the top of cmplxdivide.c.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
import (
|
| 13 |
+
"fmt"
|
| 14 |
+
"math"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
func calike(a, b complex128) bool {
|
| 18 |
+
if imag(a) != imag(b) && !(math.IsNaN(imag(a)) && math.IsNaN(imag(b))) {
|
| 19 |
+
return false
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if real(a) != real(b) && !(math.IsNaN(real(a)) && math.IsNaN(real(b))) {
|
| 23 |
+
return false
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
return true
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
func main() {
|
| 30 |
+
bad := false
|
| 31 |
+
for _, t := range tests {
|
| 32 |
+
x := t.f / t.g
|
| 33 |
+
if !calike(x, t.out) {
|
| 34 |
+
if !bad {
|
| 35 |
+
fmt.Printf("BUG\n")
|
| 36 |
+
bad = true
|
| 37 |
+
}
|
| 38 |
+
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
if bad {
|
| 42 |
+
panic("cmplxdivide failed.")
|
| 43 |
+
}
|
| 44 |
+
}
|
platform/dbops/binaries/go/go/test/cmplxdivide1.go
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
platform/dbops/binaries/go/go/test/complit.go
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test composite literals.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
type T struct {
|
| 12 |
+
i int
|
| 13 |
+
f float64
|
| 14 |
+
s string
|
| 15 |
+
next *T
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
type R struct {
|
| 19 |
+
num int
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
func itor(a int) *R {
|
| 23 |
+
r := new(R)
|
| 24 |
+
r.num = a
|
| 25 |
+
return r
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
func eq(a []*R) {
|
| 29 |
+
for i := 0; i < len(a); i++ {
|
| 30 |
+
if a[i].num != i {
|
| 31 |
+
panic("bad")
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func teq(t *T, n int) {
|
| 37 |
+
for i := 0; i < n; i++ {
|
| 38 |
+
if t == nil || t.i != i {
|
| 39 |
+
panic("bad")
|
| 40 |
+
}
|
| 41 |
+
t = t.next
|
| 42 |
+
}
|
| 43 |
+
if t != nil {
|
| 44 |
+
panic("bad")
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
type P struct {
|
| 49 |
+
a, b int
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func NewP(a, b int) *P {
|
| 53 |
+
return &P{a, b}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func main() {
|
| 57 |
+
var t T
|
| 58 |
+
t = T{0, 7.2, "hi", &t}
|
| 59 |
+
|
| 60 |
+
var tp *T
|
| 61 |
+
tp = &T{0, 7.2, "hi", &t}
|
| 62 |
+
|
| 63 |
+
tl := &T{i: 0, next: &T{i: 1, next: &T{i: 2, next: &T{i: 3, next: &T{i: 4}}}}}
|
| 64 |
+
teq(tl, 5)
|
| 65 |
+
|
| 66 |
+
a1 := []int{1, 2, 3}
|
| 67 |
+
if len(a1) != 3 {
|
| 68 |
+
panic("a1")
|
| 69 |
+
}
|
| 70 |
+
a2 := [10]int{1, 2, 3}
|
| 71 |
+
if len(a2) != 10 || cap(a2) != 10 {
|
| 72 |
+
panic("a2")
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
a3 := [10]int{1, 2, 3}
|
| 76 |
+
if len(a3) != 10 || a2[3] != 0 {
|
| 77 |
+
panic("a3")
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
var oai []int
|
| 81 |
+
oai = []int{1, 2, 3}
|
| 82 |
+
if len(oai) != 3 {
|
| 83 |
+
panic("oai")
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
at := [...]*T{&t, tp, &t}
|
| 87 |
+
if len(at) != 3 {
|
| 88 |
+
panic("at")
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
c := make(chan int)
|
| 92 |
+
ac := []chan int{c, c, c}
|
| 93 |
+
if len(ac) != 3 {
|
| 94 |
+
panic("ac")
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
aat := [][len(at)]*T{at, at}
|
| 98 |
+
if len(aat) != 2 || len(aat[1]) != 3 {
|
| 99 |
+
panic("aat")
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
s := string([]byte{'h', 'e', 'l', 'l', 'o'})
|
| 103 |
+
if s != "hello" {
|
| 104 |
+
panic("s")
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.}
|
| 108 |
+
if len(m) != 3 {
|
| 109 |
+
panic("m")
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
|
| 113 |
+
eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}})
|
| 114 |
+
|
| 115 |
+
p1 := NewP(1, 2)
|
| 116 |
+
p2 := NewP(1, 2)
|
| 117 |
+
if p1 == p2 {
|
| 118 |
+
panic("NewP")
|
| 119 |
+
}
|
| 120 |
+
}
|
platform/dbops/binaries/go/go/test/complit1.go
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that illegal composite literals are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
var m map[int][3]int
|
| 13 |
+
|
| 14 |
+
func f() [3]int
|
| 15 |
+
|
| 16 |
+
func fp() *[3]int
|
| 17 |
+
|
| 18 |
+
var mp map[int]*[3]int
|
| 19 |
+
|
| 20 |
+
var (
|
| 21 |
+
_ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value"
|
| 22 |
+
_ = m[0][:] // ERROR "slice of unaddressable value"
|
| 23 |
+
_ = f()[:] // ERROR "slice of unaddressable value"
|
| 24 |
+
|
| 25 |
+
_ = 301[:] // ERROR "cannot slice|attempt to slice object that is not"
|
| 26 |
+
_ = 3.1[:] // ERROR "cannot slice|attempt to slice object that is not"
|
| 27 |
+
_ = true[:] // ERROR "cannot slice|attempt to slice object that is not"
|
| 28 |
+
|
| 29 |
+
// these are okay because they are slicing a pointer to an array
|
| 30 |
+
_ = (&[3]int{1, 2, 3})[:]
|
| 31 |
+
_ = mp[0][:]
|
| 32 |
+
_ = fp()[:]
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
type T struct {
|
| 36 |
+
i int
|
| 37 |
+
f float64
|
| 38 |
+
s string
|
| 39 |
+
next *T
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
type TP *T
|
| 43 |
+
type Ti int
|
| 44 |
+
|
| 45 |
+
var (
|
| 46 |
+
_ = &T{0, 0, "", nil} // ok
|
| 47 |
+
_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
|
| 48 |
+
_ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal"
|
| 49 |
+
_ = TP{i: 0, f: 0, s: ""} // ERROR "invalid composite literal type TP"
|
| 50 |
+
_ = &Ti{} // ERROR "invalid composite literal type Ti|expected.*type for composite literal"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
type M map[T]T
|
| 54 |
+
|
| 55 |
+
var (
|
| 56 |
+
_ = M{{i: 1}: {i: 2}}
|
| 57 |
+
_ = M{T{i: 1}: {i: 2}}
|
| 58 |
+
_ = M{{i: 1}: T{i: 2}}
|
| 59 |
+
_ = M{T{i: 1}: T{i: 2}}
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
type S struct{ s [1]*M1 }
|
| 63 |
+
type M1 map[S]int
|
| 64 |
+
|
| 65 |
+
var _ = M1{{s: [1]*M1{&M1{{}: 1}}}: 2}
|
platform/dbops/binaries/go/go/test/compos.go
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test that returning &T{} from a function causes an allocation.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
type T struct {
|
| 12 |
+
int
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
func f() *T {
|
| 16 |
+
return &T{1}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
func main() {
|
| 20 |
+
x := f()
|
| 21 |
+
y := f()
|
| 22 |
+
if x == y {
|
| 23 |
+
panic("not allocating & composite literals")
|
| 24 |
+
}
|
| 25 |
+
}
|
platform/dbops/binaries/go/go/test/const.go
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test simple boolean and numeric constants.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import "os"
|
| 12 |
+
|
| 13 |
+
const (
|
| 14 |
+
c0 = 0
|
| 15 |
+
cm1 = -1
|
| 16 |
+
chuge = 1 << 100
|
| 17 |
+
chuge_1 = chuge - 1
|
| 18 |
+
c1 = chuge >> 100
|
| 19 |
+
c3div2 = 3 / 2
|
| 20 |
+
c1e3 = 1e3
|
| 21 |
+
|
| 22 |
+
rsh1 = 1e100 >> 1000
|
| 23 |
+
rsh2 = 1e302 >> 1000
|
| 24 |
+
|
| 25 |
+
ctrue = true
|
| 26 |
+
cfalse = !ctrue
|
| 27 |
+
|
| 28 |
+
// Issue #34563
|
| 29 |
+
_ = string(int(123))
|
| 30 |
+
_ = string(rune(456))
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
const (
|
| 34 |
+
f0 = 0.0
|
| 35 |
+
fm1 = -1.
|
| 36 |
+
fhuge float64 = 1 << 100
|
| 37 |
+
fhuge_1 float64 = chuge - 1
|
| 38 |
+
f1 float64 = chuge >> 100
|
| 39 |
+
f3div2 = 3. / 2.
|
| 40 |
+
f1e3 float64 = 1e3
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
func assert(t bool, s string) {
|
| 44 |
+
if !t {
|
| 45 |
+
panic(s)
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func ints() {
|
| 50 |
+
assert(c0 == 0, "c0")
|
| 51 |
+
assert(c1 == 1, "c1")
|
| 52 |
+
assert(chuge > chuge_1, "chuge")
|
| 53 |
+
assert(chuge_1+1 == chuge, "chuge 1")
|
| 54 |
+
assert(chuge+cm1+1 == chuge, "cm1")
|
| 55 |
+
assert(c3div2 == 1, "3/2")
|
| 56 |
+
assert(c1e3 == 1000, "c1e3 int")
|
| 57 |
+
assert(c1e3 == 1e3, "c1e3 float")
|
| 58 |
+
assert(rsh1 == 0, "rsh1")
|
| 59 |
+
assert(rsh2 == 9, "rsh2")
|
| 60 |
+
|
| 61 |
+
// verify that all (in range) are assignable as ints
|
| 62 |
+
var i int
|
| 63 |
+
i = c0
|
| 64 |
+
assert(i == c0, "i == c0")
|
| 65 |
+
i = cm1
|
| 66 |
+
assert(i == cm1, "i == cm1")
|
| 67 |
+
i = c1
|
| 68 |
+
assert(i == c1, "i == c1")
|
| 69 |
+
i = c3div2
|
| 70 |
+
assert(i == c3div2, "i == c3div2")
|
| 71 |
+
i = c1e3
|
| 72 |
+
assert(i == c1e3, "i == c1e3")
|
| 73 |
+
|
| 74 |
+
// verify that all are assignable as floats
|
| 75 |
+
var f float64
|
| 76 |
+
f = c0
|
| 77 |
+
assert(f == c0, "f == c0")
|
| 78 |
+
f = cm1
|
| 79 |
+
assert(f == cm1, "f == cm1")
|
| 80 |
+
f = chuge
|
| 81 |
+
assert(f == chuge, "f == chuge")
|
| 82 |
+
f = chuge_1
|
| 83 |
+
assert(f == chuge_1, "f == chuge_1")
|
| 84 |
+
f = c1
|
| 85 |
+
assert(f == c1, "f == c1")
|
| 86 |
+
f = c3div2
|
| 87 |
+
assert(f == c3div2, "f == c3div2")
|
| 88 |
+
f = c1e3
|
| 89 |
+
assert(f == c1e3, "f == c1e3")
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
func floats() {
|
| 93 |
+
assert(f0 == c0, "f0")
|
| 94 |
+
assert(f1 == c1, "f1")
|
| 95 |
+
// TODO(gri): exp/ssa/interp constant folding is incorrect.
|
| 96 |
+
if os.Getenv("GOSSAINTERP") == "" {
|
| 97 |
+
assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
|
| 98 |
+
}
|
| 99 |
+
assert(fhuge_1+1 == fhuge, "fhuge 1")
|
| 100 |
+
assert(fhuge+fm1+1 == fhuge, "fm1")
|
| 101 |
+
assert(f3div2 == 1.5, "3./2.")
|
| 102 |
+
assert(f1e3 == 1000, "f1e3 int")
|
| 103 |
+
assert(f1e3 == 1.e3, "f1e3 float")
|
| 104 |
+
|
| 105 |
+
// verify that all (in range) are assignable as ints
|
| 106 |
+
var i int
|
| 107 |
+
i = f0
|
| 108 |
+
assert(i == f0, "i == f0")
|
| 109 |
+
i = fm1
|
| 110 |
+
assert(i == fm1, "i == fm1")
|
| 111 |
+
|
| 112 |
+
// verify that all are assignable as floats
|
| 113 |
+
var f float64
|
| 114 |
+
f = f0
|
| 115 |
+
assert(f == f0, "f == f0")
|
| 116 |
+
f = fm1
|
| 117 |
+
assert(f == fm1, "f == fm1")
|
| 118 |
+
f = fhuge
|
| 119 |
+
assert(f == fhuge, "f == fhuge")
|
| 120 |
+
f = fhuge_1
|
| 121 |
+
assert(f == fhuge_1, "f == fhuge_1")
|
| 122 |
+
f = f1
|
| 123 |
+
assert(f == f1, "f == f1")
|
| 124 |
+
f = f3div2
|
| 125 |
+
assert(f == f3div2, "f == f3div2")
|
| 126 |
+
f = f1e3
|
| 127 |
+
assert(f == f1e3, "f == f1e3")
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
func interfaces() {
|
| 131 |
+
var (
|
| 132 |
+
nilN interface{}
|
| 133 |
+
nilI *int
|
| 134 |
+
five = 5
|
| 135 |
+
|
| 136 |
+
_ = nil == interface{}(nil)
|
| 137 |
+
_ = interface{}(nil) == nil
|
| 138 |
+
)
|
| 139 |
+
ii := func(i1 interface{}, i2 interface{}) bool { return i1 == i2 }
|
| 140 |
+
ni := func(n interface{}, i int) bool { return n == i }
|
| 141 |
+
in := func(i int, n interface{}) bool { return i == n }
|
| 142 |
+
pi := func(p *int, i interface{}) bool { return p == i }
|
| 143 |
+
ip := func(i interface{}, p *int) bool { return i == p }
|
| 144 |
+
|
| 145 |
+
assert((interface{}(nil) == interface{}(nil)) == ii(nilN, nilN),
|
| 146 |
+
"for interface{}==interface{} compiler == runtime")
|
| 147 |
+
|
| 148 |
+
assert(((*int)(nil) == interface{}(nil)) == pi(nilI, nilN),
|
| 149 |
+
"for *int==interface{} compiler == runtime")
|
| 150 |
+
assert((interface{}(nil) == (*int)(nil)) == ip(nilN, nilI),
|
| 151 |
+
"for interface{}==*int compiler == runtime")
|
| 152 |
+
|
| 153 |
+
assert((&five == interface{}(nil)) == pi(&five, nilN),
|
| 154 |
+
"for interface{}==*int compiler == runtime")
|
| 155 |
+
assert((interface{}(nil) == &five) == ip(nilN, &five),
|
| 156 |
+
"for interface{}==*int compiler == runtime")
|
| 157 |
+
|
| 158 |
+
assert((5 == interface{}(5)) == ni(five, five),
|
| 159 |
+
"for int==interface{} compiler == runtime")
|
| 160 |
+
assert((interface{}(5) == 5) == in(five, five),
|
| 161 |
+
"for interface{}==int comipiler == runtime")
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// Test that typed floating-point and complex arithmetic
|
| 165 |
+
// is computed with correct precision.
|
| 166 |
+
func truncate() {
|
| 167 |
+
const (
|
| 168 |
+
x30 = 1 << 30
|
| 169 |
+
x60 = 1 << 60
|
| 170 |
+
|
| 171 |
+
staticF32 = float32(x30) + 1 - x30
|
| 172 |
+
staticF64 = float64(x60) + 1 - x60
|
| 173 |
+
staticC64 = complex64(x30) + 1 - x30
|
| 174 |
+
staticC128 = complex128(x60) + 1 - x60
|
| 175 |
+
)
|
| 176 |
+
dynamicF32 := float32(x30)
|
| 177 |
+
dynamicF32 += 1
|
| 178 |
+
dynamicF32 -= x30
|
| 179 |
+
|
| 180 |
+
dynamicF64 := float64(x60)
|
| 181 |
+
dynamicF64 += 1
|
| 182 |
+
dynamicF64 -= x60
|
| 183 |
+
|
| 184 |
+
dynamicC64 := complex64(x30)
|
| 185 |
+
dynamicC64 += 1
|
| 186 |
+
dynamicC64 -= x30
|
| 187 |
+
|
| 188 |
+
dynamicC128 := complex128(x60)
|
| 189 |
+
dynamicC128 += 1
|
| 190 |
+
dynamicC128 -= x60
|
| 191 |
+
|
| 192 |
+
assert(staticF32 == 0, "staticF32 == 0")
|
| 193 |
+
assert(staticF64 == 0, "staticF64 == 0")
|
| 194 |
+
assert(dynamicF32 == 0, "dynamicF32 == 0")
|
| 195 |
+
assert(dynamicF64 == 0, "dynamicF64 == 0")
|
| 196 |
+
assert(staticC64 == 0, "staticC64 == 0")
|
| 197 |
+
assert(staticC128 == 0, "staticC128 == 0")
|
| 198 |
+
assert(dynamicC64 == 0, "dynamicC64 == 0")
|
| 199 |
+
assert(dynamicC128 == 0, "dynamicC128 == 0")
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
func main() {
|
| 203 |
+
ints()
|
| 204 |
+
floats()
|
| 205 |
+
interfaces()
|
| 206 |
+
truncate()
|
| 207 |
+
|
| 208 |
+
assert(ctrue == true, "ctrue == true")
|
| 209 |
+
assert(cfalse == false, "cfalse == false")
|
| 210 |
+
}
|
platform/dbops/binaries/go/go/test/const1.go
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify overflow is detected when using numeric constants.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
import "unsafe"
|
| 13 |
+
|
| 14 |
+
type I interface{}
|
| 15 |
+
|
| 16 |
+
const (
|
| 17 |
+
// assume all types behave similarly to int8/uint8
|
| 18 |
+
Int8 int8 = 101
|
| 19 |
+
Minus1 int8 = -1
|
| 20 |
+
Uint8 uint8 = 102
|
| 21 |
+
Const = 103
|
| 22 |
+
|
| 23 |
+
Float32 float32 = 104.5
|
| 24 |
+
Float64 float64 = 105.5
|
| 25 |
+
ConstFloat = 106.5
|
| 26 |
+
Big float64 = 1e300
|
| 27 |
+
|
| 28 |
+
String = "abc"
|
| 29 |
+
Bool = true
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
var (
|
| 33 |
+
a1 = Int8 * 100 // ERROR "overflow|cannot convert"
|
| 34 |
+
a2 = Int8 * -1 // OK
|
| 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"
|
| 41 |
+
a9 = Int8 * (Const / 100) // OK
|
| 42 |
+
|
| 43 |
+
b1 = Uint8 * Uint8 // ERROR "overflow|cannot convert"
|
| 44 |
+
b2 = Uint8 * -1 // ERROR "overflow|cannot convert"
|
| 45 |
+
b3 = Uint8 - Uint8 // OK
|
| 46 |
+
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow|cannot convert"
|
| 47 |
+
b5 = uint8(^0) // ERROR "overflow|cannot convert"
|
| 48 |
+
b5a = int64(^0) // OK
|
| 49 |
+
b6 = ^uint8(0) // OK
|
| 50 |
+
b6a = ^int64(0) // OK
|
| 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"
|
| 54 |
+
b9 byte = (1 << 10) >> 8 // OK
|
| 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"
|
| 62 |
+
b16a byte = 0 * 1000 // OK
|
| 63 |
+
b17 byte = byte(0) * byte(1000) // ERROR "overflow|cannot convert"
|
| 64 |
+
b18 byte = Uint8 / 0 // ERROR "division by zero"
|
| 65 |
+
|
| 66 |
+
c1 float64 = Big
|
| 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"
|
| 70 |
+
c5 = Big / 0 // ERROR "division by zero"
|
| 71 |
+
c6 = 1000 % 1e3 // ERROR "invalid operation|expected integer type"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
func f(int)
|
| 75 |
+
|
| 76 |
+
func main() {
|
| 77 |
+
f(Int8) // ERROR "convert|wrong type|cannot"
|
| 78 |
+
f(Minus1) // ERROR "convert|wrong type|cannot"
|
| 79 |
+
f(Uint8) // ERROR "convert|wrong type|cannot"
|
| 80 |
+
f(Const) // OK
|
| 81 |
+
f(Float32) // ERROR "convert|wrong type|cannot"
|
| 82 |
+
f(Float64) // ERROR "convert|wrong type|cannot"
|
| 83 |
+
f(ConstFloat) // ERROR "truncate"
|
| 84 |
+
f(ConstFloat - 0.5) // OK
|
| 85 |
+
f(Big) // ERROR "convert|wrong type|cannot"
|
| 86 |
+
f(String) // ERROR "convert|wrong type|cannot|incompatible"
|
| 87 |
+
f(Bool) // ERROR "convert|wrong type|cannot|incompatible"
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
const ptr = nil // ERROR "const.*nil|not constant"
|
| 91 |
+
const _ = string([]byte(nil)) // ERROR "is not a? ?constant"
|
| 92 |
+
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|not constant"
|
| 94 |
+
const _ = (*int)(nil) // ERROR "cannot be nil|invalid constant type|is not a constant|not constant"
|
platform/dbops/binaries/go/go/test/const2.go
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that large integer constant expressions cause overflow.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
const (
|
| 13 |
+
A int = 1
|
| 14 |
+
B byte; // ERROR "type without expr|expected .=.|missing init expr"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
const LargeA = 1000000000000000000
|
| 18 |
+
const LargeB = LargeA * LargeA * LargeA
|
| 19 |
+
const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
|
| 20 |
+
|
| 21 |
+
const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"
|
| 22 |
+
|
| 23 |
+
// Issue #42732.
|
| 24 |
+
|
| 25 |
+
const a = 1e+500000000
|
| 26 |
+
const b = a * a // ERROR "constant multiplication overflow|not representable"
|
| 27 |
+
const c = b * b
|
| 28 |
+
|
| 29 |
+
const MaxInt512 = (1<<256 - 1) * (1<<256 + 1)
|
| 30 |
+
const _ = MaxInt512 + 1 // ERROR "constant addition overflow"
|
| 31 |
+
const _ = MaxInt512 ^ -1 // ERROR "constant bitwise XOR overflow"
|
| 32 |
+
const _ = ^MaxInt512 // ERROR "constant bitwise complement overflow"
|
platform/dbops/binaries/go/go/test/const3.go
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test typed integer constants.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import "fmt"
|
| 12 |
+
|
| 13 |
+
type T int
|
| 14 |
+
|
| 15 |
+
func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
|
| 16 |
+
|
| 17 |
+
const (
|
| 18 |
+
A T = 1 << (1 << iota)
|
| 19 |
+
B
|
| 20 |
+
C
|
| 21 |
+
D
|
| 22 |
+
E
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
func main() {
|
| 26 |
+
s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
|
| 27 |
+
if s != "T2 T4 T16 T256 T65536" {
|
| 28 |
+
println("type info didn't propagate in const: got", s)
|
| 29 |
+
panic("fail")
|
| 30 |
+
}
|
| 31 |
+
x := uint(5)
|
| 32 |
+
y := float64(uint64(1)<<x) // used to fail to compile
|
| 33 |
+
if y != 32 {
|
| 34 |
+
println("wrong y", y)
|
| 35 |
+
panic("fail")
|
| 36 |
+
}
|
| 37 |
+
}
|
platform/dbops/binaries/go/go/test/const4.go
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test len constants and non-constants, https://golang.org/issue/3244.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
var b struct {
|
| 12 |
+
a [10]int
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
var m map[string][20]int
|
| 16 |
+
|
| 17 |
+
var s [][30]int
|
| 18 |
+
|
| 19 |
+
const (
|
| 20 |
+
n1 = len(b.a)
|
| 21 |
+
n2 = len(m[""])
|
| 22 |
+
n3 = len(s[10])
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
// Non-constants (see also const5.go).
|
| 26 |
+
var (
|
| 27 |
+
n4 = len(f())
|
| 28 |
+
n5 = len(<-c)
|
| 29 |
+
n6 = cap(g())
|
| 30 |
+
n7 = cap(<-c1)
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
var calledF = false
|
| 34 |
+
|
| 35 |
+
func f() *[40]int {
|
| 36 |
+
calledF = true
|
| 37 |
+
return nil
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
var c = func() chan *[50]int {
|
| 41 |
+
c := make(chan *[50]int, 2)
|
| 42 |
+
c <- nil
|
| 43 |
+
c <- new([50]int)
|
| 44 |
+
return c
|
| 45 |
+
}()
|
| 46 |
+
|
| 47 |
+
var calledG = false
|
| 48 |
+
|
| 49 |
+
func g() *[60]int {
|
| 50 |
+
calledG = true
|
| 51 |
+
return nil
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
var c1 = func() chan *[70]int {
|
| 55 |
+
c := make(chan *[70]int, 2)
|
| 56 |
+
c <- nil
|
| 57 |
+
c <- new([70]int)
|
| 58 |
+
return c
|
| 59 |
+
}()
|
| 60 |
+
|
| 61 |
+
func main() {
|
| 62 |
+
if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {
|
| 63 |
+
println("BUG:", n1, n2, n3, n4, n5, n6, n7)
|
| 64 |
+
panic("fail")
|
| 65 |
+
}
|
| 66 |
+
if !calledF {
|
| 67 |
+
println("BUG: did not call f")
|
| 68 |
+
panic("fail")
|
| 69 |
+
}
|
| 70 |
+
if <-c == nil {
|
| 71 |
+
println("BUG: did not receive from c")
|
| 72 |
+
panic("fail")
|
| 73 |
+
}
|
| 74 |
+
if !calledG {
|
| 75 |
+
println("BUG: did not call g")
|
| 76 |
+
panic("fail")
|
| 77 |
+
}
|
| 78 |
+
if <-c1 == nil {
|
| 79 |
+
println("BUG: did not receive from c1")
|
| 80 |
+
panic("fail")
|
| 81 |
+
}
|
| 82 |
+
}
|
platform/dbops/binaries/go/go/test/const5.go
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test that len non-constants are not constants, https://golang.org/issue/3244.
|
| 8 |
+
|
| 9 |
+
package p
|
| 10 |
+
|
| 11 |
+
var b struct {
|
| 12 |
+
a[10]int
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
var m map[string][20]int
|
| 16 |
+
|
| 17 |
+
var s [][30]int
|
| 18 |
+
|
| 19 |
+
func f() *[40]int
|
| 20 |
+
var c chan *[50]int
|
| 21 |
+
var z complex128
|
| 22 |
+
|
| 23 |
+
const (
|
| 24 |
+
n1 = len(b.a)
|
| 25 |
+
n2 = len(m[""])
|
| 26 |
+
n3 = len(s[10])
|
| 27 |
+
|
| 28 |
+
n4 = len(f()) // ERROR "is not a constant|is not constant"
|
| 29 |
+
n5 = len(<-c) // ERROR "is not a constant|is not constant"
|
| 30 |
+
|
| 31 |
+
n6 = cap(f()) // ERROR "is not a constant|is not constant"
|
| 32 |
+
n7 = cap(<-c) // ERROR "is not a constant|is not constant"
|
| 33 |
+
n8 = real(z) // ERROR "is not a constant|is not constant"
|
| 34 |
+
n9 = len([4]float64{real(z)}) // ERROR "is not a constant|is not constant"
|
| 35 |
+
|
| 36 |
+
)
|
| 37 |
+
|
platform/dbops/binaries/go/go/test/const6.go
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2013 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Ideal vs non-ideal bool. See issue 3915, 3923.
|
| 8 |
+
|
| 9 |
+
package p
|
| 10 |
+
|
| 11 |
+
type mybool bool
|
| 12 |
+
type mybool1 bool
|
| 13 |
+
|
| 14 |
+
var (
|
| 15 |
+
x, y int = 1, 2
|
| 16 |
+
c1 bool = x < y
|
| 17 |
+
c2 mybool = x < y
|
| 18 |
+
c3 mybool = c2 == (x < y)
|
| 19 |
+
c4 mybool = c2 == (1 < 2)
|
| 20 |
+
c5 mybool = 1 < 2
|
| 21 |
+
c6 mybool1 = x < y
|
| 22 |
+
c7 = c1 == c2 // ERROR "mismatched types|incompatible types"
|
| 23 |
+
c8 = c2 == c6 // ERROR "mismatched types|incompatible types"
|
| 24 |
+
c9 = c1 == c6 // ERROR "mismatched types|incompatible types"
|
| 25 |
+
_ = c2 && (x < y)
|
| 26 |
+
_ = c2 && (1 < 2)
|
| 27 |
+
_ = c1 && c2 // ERROR "mismatched types|incompatible types"
|
| 28 |
+
_ = c2 && c6 // ERROR "mismatched types|incompatible types"
|
| 29 |
+
_ = c1 && c6 // ERROR "mismatched types|incompatible types"
|
| 30 |
+
)
|
platform/dbops/binaries/go/go/test/const7.go
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2021 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Check that the compiler refuses excessively long constants.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"bytes"
|
| 13 |
+
"fmt"
|
| 14 |
+
"io/ioutil"
|
| 15 |
+
"log"
|
| 16 |
+
"os"
|
| 17 |
+
"os/exec"
|
| 18 |
+
"path/filepath"
|
| 19 |
+
"runtime"
|
| 20 |
+
"strings"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
// testProg creates a package called name, with path dir/name.go,
|
| 24 |
+
// which declares an untyped constant of the given length.
|
| 25 |
+
// testProg compiles this package and checks for the absence or
|
| 26 |
+
// presence of a constant literal error.
|
| 27 |
+
func testProg(dir, name string, length int, msg string) {
|
| 28 |
+
var buf bytes.Buffer
|
| 29 |
+
|
| 30 |
+
fmt.Fprintf(&buf,
|
| 31 |
+
"package %s; const _ = 0b%s // %d bits",
|
| 32 |
+
name, strings.Repeat("1", length), length,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
filename := filepath.Join(dir, fmt.Sprintf("%s.go", name))
|
| 36 |
+
if err := os.WriteFile(filename, buf.Bytes(), 0666); err != nil {
|
| 37 |
+
log.Fatal(err)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
cmd := exec.Command("go", "tool", "compile", "-p=p", filename)
|
| 41 |
+
cmd.Dir = dir
|
| 42 |
+
output, err := cmd.CombinedOutput()
|
| 43 |
+
|
| 44 |
+
if msg == "" {
|
| 45 |
+
// no error expected
|
| 46 |
+
if err != nil {
|
| 47 |
+
log.Fatalf("%s: compile failed unexpectedly: %v", name, err)
|
| 48 |
+
}
|
| 49 |
+
return
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// error expected
|
| 53 |
+
if err == nil {
|
| 54 |
+
log.Fatalf("%s: compile succeeded unexpectedly", name)
|
| 55 |
+
}
|
| 56 |
+
if !bytes.Contains(output, []byte(msg)) {
|
| 57 |
+
log.Fatalf("%s: wrong compiler error message:\n%s\n", name, output)
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func main() {
|
| 62 |
+
if runtime.GOOS == "js" || runtime.GOOS == "wasip1" || runtime.Compiler != "gc" {
|
| 63 |
+
return
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
dir, err := ioutil.TempDir("", "const7_")
|
| 67 |
+
if err != nil {
|
| 68 |
+
log.Fatalf("creating temp dir: %v\n", err)
|
| 69 |
+
}
|
| 70 |
+
defer os.RemoveAll(dir)
|
| 71 |
+
|
| 72 |
+
const bitLimit = 512
|
| 73 |
+
const charLimit = 10000 // compiler-internal constant length limit
|
| 74 |
+
testProg(dir, "x1", bitLimit, "")
|
| 75 |
+
testProg(dir, "x2", bitLimit+1, "constant overflow")
|
| 76 |
+
testProg(dir, "x3", charLimit-2, "constant overflow") // -2 because literal contains 0b prefix
|
| 77 |
+
testProg(dir, "x4", charLimit-1, "excessively long constant")
|
| 78 |
+
}
|
platform/dbops/binaries/go/go/test/const8.go
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test that identifiers in implicit (omitted) RHS
|
| 8 |
+
// expressions of constant declarations are resolved
|
| 9 |
+
// in the correct context; see issues #49157, #53585.
|
| 10 |
+
|
| 11 |
+
package main
|
| 12 |
+
|
| 13 |
+
const X = 2
|
| 14 |
+
|
| 15 |
+
func main() {
|
| 16 |
+
const (
|
| 17 |
+
A = iota // 0
|
| 18 |
+
iota = iota // 1
|
| 19 |
+
B // 1 (iota is declared locally on prev. line)
|
| 20 |
+
C // 1
|
| 21 |
+
)
|
| 22 |
+
if A != 0 || B != 1 || C != 1 {
|
| 23 |
+
println("got", A, B, C, "want 0 1 1")
|
| 24 |
+
panic("FAILED")
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const (
|
| 28 |
+
X = X + X
|
| 29 |
+
Y
|
| 30 |
+
Z = iota
|
| 31 |
+
)
|
| 32 |
+
if X != 4 || Y != 8 || Z != 1 {
|
| 33 |
+
println("got", X, Y, Z, "want 4 8 1")
|
| 34 |
+
panic("FAILED")
|
| 35 |
+
}
|
| 36 |
+
}
|
platform/dbops/binaries/go/go/test/convT2X.go
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2012 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test conversion from non-interface types to the empty interface.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
type J interface {
|
| 12 |
+
Method()
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
type (
|
| 16 |
+
U16 uint16
|
| 17 |
+
U32 uint32
|
| 18 |
+
U64 uint64
|
| 19 |
+
U128 [2]uint64
|
| 20 |
+
F32 float32
|
| 21 |
+
F64 float64
|
| 22 |
+
C128 complex128
|
| 23 |
+
S string
|
| 24 |
+
B []byte
|
| 25 |
+
M map[int]int
|
| 26 |
+
C chan int
|
| 27 |
+
Z struct{}
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
func (U16) Method() {}
|
| 31 |
+
func (U32) Method() {}
|
| 32 |
+
func (U64) Method() {}
|
| 33 |
+
func (U128) Method() {}
|
| 34 |
+
func (F32) Method() {}
|
| 35 |
+
func (F64) Method() {}
|
| 36 |
+
func (C128) Method() {}
|
| 37 |
+
func (S) Method() {}
|
| 38 |
+
func (B) Method() {}
|
| 39 |
+
func (M) Method() {}
|
| 40 |
+
func (C) Method() {}
|
| 41 |
+
func (Z) Method() {}
|
| 42 |
+
|
| 43 |
+
var (
|
| 44 |
+
u16 = U16(1)
|
| 45 |
+
u32 = U32(2)
|
| 46 |
+
u64 = U64(3)
|
| 47 |
+
u128 = U128{4, 5}
|
| 48 |
+
f32 = F32(6)
|
| 49 |
+
f64 = F64(7)
|
| 50 |
+
c128 = C128(8 + 9i)
|
| 51 |
+
s = S("10")
|
| 52 |
+
b = B("11")
|
| 53 |
+
m = M{12: 13}
|
| 54 |
+
c = make(C, 14)
|
| 55 |
+
z = Z{}
|
| 56 |
+
p = &z
|
| 57 |
+
pp = &p
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
var (
|
| 61 |
+
iu16 interface{} = u16
|
| 62 |
+
iu32 interface{} = u32
|
| 63 |
+
iu64 interface{} = u64
|
| 64 |
+
iu128 interface{} = u128
|
| 65 |
+
if32 interface{} = f32
|
| 66 |
+
if64 interface{} = f64
|
| 67 |
+
ic128 interface{} = c128
|
| 68 |
+
is interface{} = s
|
| 69 |
+
ib interface{} = b
|
| 70 |
+
im interface{} = m
|
| 71 |
+
ic interface{} = c
|
| 72 |
+
iz interface{} = z
|
| 73 |
+
ip interface{} = p
|
| 74 |
+
ipp interface{} = pp
|
| 75 |
+
|
| 76 |
+
ju16 J = u16
|
| 77 |
+
ju32 J = u32
|
| 78 |
+
ju64 J = u64
|
| 79 |
+
ju128 J = u128
|
| 80 |
+
jf32 J = f32
|
| 81 |
+
jf64 J = f64
|
| 82 |
+
jc128 J = c128
|
| 83 |
+
js J = s
|
| 84 |
+
jb J = b
|
| 85 |
+
jm J = m
|
| 86 |
+
jc J = c
|
| 87 |
+
jz J = z
|
| 88 |
+
jp J = p // The method set for *T contains the methods for T.
|
| 89 |
+
// pp does not implement error.
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
func second(a ...interface{}) interface{} {
|
| 93 |
+
return a[1]
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
func main() {
|
| 97 |
+
// Test equality.
|
| 98 |
+
if u16 != iu16 {
|
| 99 |
+
panic("u16 != iu16")
|
| 100 |
+
}
|
| 101 |
+
if u16 != ju16 {
|
| 102 |
+
panic("u16 != ju16")
|
| 103 |
+
}
|
| 104 |
+
if u32 != iu32 {
|
| 105 |
+
panic("u32 != iu32")
|
| 106 |
+
}
|
| 107 |
+
if u32 != ju32 {
|
| 108 |
+
panic("u32 != ju32")
|
| 109 |
+
}
|
| 110 |
+
if u64 != iu64 {
|
| 111 |
+
panic("u64 != iu64")
|
| 112 |
+
}
|
| 113 |
+
if u64 != ju64 {
|
| 114 |
+
panic("u64 != ju64")
|
| 115 |
+
}
|
| 116 |
+
if u128 != iu128 {
|
| 117 |
+
panic("u128 != iu128")
|
| 118 |
+
}
|
| 119 |
+
if u128 != ju128 {
|
| 120 |
+
panic("u128 != ju128")
|
| 121 |
+
}
|
| 122 |
+
if f32 != if32 {
|
| 123 |
+
panic("f32 != if32")
|
| 124 |
+
}
|
| 125 |
+
if f32 != jf32 {
|
| 126 |
+
panic("f32 != jf32")
|
| 127 |
+
}
|
| 128 |
+
if f64 != if64 {
|
| 129 |
+
panic("f64 != if64")
|
| 130 |
+
}
|
| 131 |
+
if f64 != jf64 {
|
| 132 |
+
panic("f64 != jf64")
|
| 133 |
+
}
|
| 134 |
+
if c128 != ic128 {
|
| 135 |
+
panic("c128 != ic128")
|
| 136 |
+
}
|
| 137 |
+
if c128 != jc128 {
|
| 138 |
+
panic("c128 != jc128")
|
| 139 |
+
}
|
| 140 |
+
if s != is {
|
| 141 |
+
panic("s != is")
|
| 142 |
+
}
|
| 143 |
+
if s != js {
|
| 144 |
+
panic("s != js")
|
| 145 |
+
}
|
| 146 |
+
if c != ic {
|
| 147 |
+
panic("c != ic")
|
| 148 |
+
}
|
| 149 |
+
if c != jc {
|
| 150 |
+
panic("c != jc")
|
| 151 |
+
}
|
| 152 |
+
// There are no tests for b and m, as slices and maps are not comparable by ==.
|
| 153 |
+
if z != iz {
|
| 154 |
+
panic("z != iz")
|
| 155 |
+
}
|
| 156 |
+
if z != jz {
|
| 157 |
+
panic("z != jz")
|
| 158 |
+
}
|
| 159 |
+
if p != ip {
|
| 160 |
+
panic("p != ip")
|
| 161 |
+
}
|
| 162 |
+
if p != jp {
|
| 163 |
+
panic("p != jp")
|
| 164 |
+
}
|
| 165 |
+
if pp != ipp {
|
| 166 |
+
panic("pp != ipp")
|
| 167 |
+
}
|
| 168 |
+
// pp does not implement J.
|
| 169 |
+
|
| 170 |
+
// Test that non-interface types can be used as ...interface{} arguments.
|
| 171 |
+
if got := second(z, p, pp, u16, u32, u64, u128, f32, f64, c128, s, b, m, c); got != ip {
|
| 172 |
+
println("second: got", got, "want", ip)
|
| 173 |
+
panic("fail")
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// Test that non-interface types can be sent on a chan interface{}.
|
| 177 |
+
const n = 100
|
| 178 |
+
uc := make(chan interface{})
|
| 179 |
+
go func() {
|
| 180 |
+
for i := 0; i < n; i++ {
|
| 181 |
+
select {
|
| 182 |
+
case uc <- nil:
|
| 183 |
+
case uc <- u32:
|
| 184 |
+
case uc <- u64:
|
| 185 |
+
case uc <- u128:
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
}()
|
| 189 |
+
for i := 0; i < n; i++ {
|
| 190 |
+
if got := <-uc; got != nil && got != u32 && got != u64 && got != u128 {
|
| 191 |
+
println("recv: i", i, "got", got)
|
| 192 |
+
panic("fail")
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
}
|
platform/dbops/binaries/go/go/test/convert.go
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test types of constant expressions, using reflect.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import "reflect"
|
| 12 |
+
|
| 13 |
+
func typeof(x interface{}) string { return reflect.TypeOf(x).String() }
|
| 14 |
+
|
| 15 |
+
func f() int { return 0 }
|
| 16 |
+
|
| 17 |
+
func g() int { return 0 }
|
| 18 |
+
|
| 19 |
+
type T func() int
|
| 20 |
+
|
| 21 |
+
var m = map[string]T{"f": f}
|
| 22 |
+
|
| 23 |
+
type A int
|
| 24 |
+
type B int
|
| 25 |
+
|
| 26 |
+
var a A = 1
|
| 27 |
+
var b B = 2
|
| 28 |
+
var x int
|
| 29 |
+
|
| 30 |
+
func main() {
|
| 31 |
+
want := typeof(g)
|
| 32 |
+
if t := typeof(f); t != want {
|
| 33 |
+
println("type of f is", t, "want", want)
|
| 34 |
+
panic("fail")
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
want = typeof(a)
|
| 38 |
+
if t := typeof(+a); t != want {
|
| 39 |
+
println("type of +a is", t, "want", want)
|
| 40 |
+
panic("fail")
|
| 41 |
+
}
|
| 42 |
+
if t := typeof(a + 0); t != want {
|
| 43 |
+
println("type of a+0 is", t, "want", want)
|
| 44 |
+
panic("fail")
|
| 45 |
+
}
|
| 46 |
+
}
|
platform/dbops/binaries/go/go/test/convert1.go
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that illegal conversions involving strings are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
type Tbyte []byte
|
| 13 |
+
type Trune []rune
|
| 14 |
+
type Tint64 []int64
|
| 15 |
+
type Tstring string
|
| 16 |
+
|
| 17 |
+
func main() {
|
| 18 |
+
s := "hello"
|
| 19 |
+
sb := []byte("hello")
|
| 20 |
+
sr := []rune("hello")
|
| 21 |
+
si := []int64{'h', 'e', 'l', 'l', 'o'}
|
| 22 |
+
|
| 23 |
+
ts := Tstring(s)
|
| 24 |
+
tsb := Tbyte(sb)
|
| 25 |
+
tsr := Trune(sr)
|
| 26 |
+
tsi := Tint64(si)
|
| 27 |
+
|
| 28 |
+
_ = string(s)
|
| 29 |
+
_ = []byte(s)
|
| 30 |
+
_ = []rune(s)
|
| 31 |
+
_ = []int64(s) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 32 |
+
_ = Tstring(s)
|
| 33 |
+
_ = Tbyte(s)
|
| 34 |
+
_ = Trune(s)
|
| 35 |
+
_ = Tint64(s) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 36 |
+
|
| 37 |
+
_ = string(sb)
|
| 38 |
+
_ = []byte(sb)
|
| 39 |
+
_ = []rune(sb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
|
| 40 |
+
_ = []int64(sb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 41 |
+
_ = Tstring(sb)
|
| 42 |
+
_ = Tbyte(sb)
|
| 43 |
+
_ = Trune(sb) // ERROR "cannot convert.*Trune|invalid type conversion"
|
| 44 |
+
_ = Tint64(sb) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 45 |
+
|
| 46 |
+
_ = string(sr)
|
| 47 |
+
_ = []byte(sr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
|
| 48 |
+
_ = []rune(sr)
|
| 49 |
+
_ = []int64(sr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 50 |
+
_ = Tstring(sr)
|
| 51 |
+
_ = Tbyte(sr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
|
| 52 |
+
_ = Trune(sr)
|
| 53 |
+
_ = Tint64(sr) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 54 |
+
|
| 55 |
+
_ = string(si) // ERROR "cannot convert.* string|invalid type conversion"
|
| 56 |
+
_ = []byte(si) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
|
| 57 |
+
_ = []rune(si) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
|
| 58 |
+
_ = []int64(si)
|
| 59 |
+
_ = Tstring(si) // ERROR "cannot convert.*Tstring|invalid type conversion"
|
| 60 |
+
_ = Tbyte(si) // ERROR "cannot convert.*Tbyte|invalid type conversion"
|
| 61 |
+
_ = Trune(si) // ERROR "cannot convert.*Trune|invalid type conversion"
|
| 62 |
+
_ = Tint64(si)
|
| 63 |
+
|
| 64 |
+
_ = string(ts)
|
| 65 |
+
_ = []byte(ts)
|
| 66 |
+
_ = []rune(ts)
|
| 67 |
+
_ = []int64(ts) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 68 |
+
_ = Tstring(ts)
|
| 69 |
+
_ = Tbyte(ts)
|
| 70 |
+
_ = Trune(ts)
|
| 71 |
+
_ = Tint64(ts) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 72 |
+
|
| 73 |
+
_ = string(tsb)
|
| 74 |
+
_ = []byte(tsb)
|
| 75 |
+
_ = []rune(tsb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
|
| 76 |
+
_ = []int64(tsb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 77 |
+
_ = Tstring(tsb)
|
| 78 |
+
_ = Tbyte(tsb)
|
| 79 |
+
_ = Trune(tsb) // ERROR "cannot convert.*Trune|invalid type conversion"
|
| 80 |
+
_ = Tint64(tsb) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 81 |
+
|
| 82 |
+
_ = string(tsr)
|
| 83 |
+
_ = []byte(tsr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
|
| 84 |
+
_ = []rune(tsr)
|
| 85 |
+
_ = []int64(tsr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
|
| 86 |
+
_ = Tstring(tsr)
|
| 87 |
+
_ = Tbyte(tsr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
|
| 88 |
+
_ = Trune(tsr)
|
| 89 |
+
_ = Tint64(tsr) // ERROR "cannot convert.*Tint64|invalid type conversion"
|
| 90 |
+
|
| 91 |
+
_ = string(tsi) // ERROR "cannot convert.* string|invalid type conversion"
|
| 92 |
+
_ = []byte(tsi) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
|
| 93 |
+
_ = []rune(tsi) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
|
| 94 |
+
_ = []int64(tsi)
|
| 95 |
+
_ = Tstring(tsi) // ERROR "cannot convert.*Tstring|invalid type conversion"
|
| 96 |
+
_ = Tbyte(tsi) // ERROR "cannot convert.*Tbyte|invalid type conversion"
|
| 97 |
+
_ = Trune(tsi) // ERROR "cannot convert.*Trune|invalid type conversion"
|
| 98 |
+
_ = Tint64(tsi)
|
| 99 |
+
}
|
platform/dbops/binaries/go/go/test/convert2.go
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test various valid and invalid struct assignments and conversions.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
type I interface {
|
| 13 |
+
m()
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// conversions between structs
|
| 17 |
+
|
| 18 |
+
func _() {
|
| 19 |
+
type S struct{}
|
| 20 |
+
type T struct{}
|
| 21 |
+
var s S
|
| 22 |
+
var t T
|
| 23 |
+
var u struct{}
|
| 24 |
+
s = s
|
| 25 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 26 |
+
s = u
|
| 27 |
+
s = S(s)
|
| 28 |
+
s = S(t)
|
| 29 |
+
s = S(u)
|
| 30 |
+
t = u
|
| 31 |
+
t = T(u)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
func _() {
|
| 35 |
+
type S struct{ x int }
|
| 36 |
+
type T struct {
|
| 37 |
+
x int "foo"
|
| 38 |
+
}
|
| 39 |
+
var s S
|
| 40 |
+
var t T
|
| 41 |
+
var u struct {
|
| 42 |
+
x int "bar"
|
| 43 |
+
}
|
| 44 |
+
s = s
|
| 45 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 46 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 47 |
+
s = S(s)
|
| 48 |
+
s = S(t)
|
| 49 |
+
s = S(u)
|
| 50 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 51 |
+
t = T(u)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func _() {
|
| 55 |
+
type E struct{ x int }
|
| 56 |
+
type S struct{ x E }
|
| 57 |
+
type T struct {
|
| 58 |
+
x E "foo"
|
| 59 |
+
}
|
| 60 |
+
var s S
|
| 61 |
+
var t T
|
| 62 |
+
var u struct {
|
| 63 |
+
x E "bar"
|
| 64 |
+
}
|
| 65 |
+
s = s
|
| 66 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 67 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 68 |
+
s = S(s)
|
| 69 |
+
s = S(t)
|
| 70 |
+
s = S(u)
|
| 71 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 72 |
+
t = T(u)
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
func _() {
|
| 76 |
+
type S struct {
|
| 77 |
+
x struct {
|
| 78 |
+
x int "foo"
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
type T struct {
|
| 82 |
+
x struct {
|
| 83 |
+
x int "bar"
|
| 84 |
+
} "foo"
|
| 85 |
+
}
|
| 86 |
+
var s S
|
| 87 |
+
var t T
|
| 88 |
+
var u struct {
|
| 89 |
+
x struct {
|
| 90 |
+
x int "bar"
|
| 91 |
+
} "bar"
|
| 92 |
+
}
|
| 93 |
+
s = s
|
| 94 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 95 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 96 |
+
s = S(s)
|
| 97 |
+
s = S(t)
|
| 98 |
+
s = S(u)
|
| 99 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 100 |
+
t = T(u)
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
func _() {
|
| 104 |
+
type E1 struct {
|
| 105 |
+
x int "foo"
|
| 106 |
+
}
|
| 107 |
+
type E2 struct {
|
| 108 |
+
x int "bar"
|
| 109 |
+
}
|
| 110 |
+
type S struct{ x E1 }
|
| 111 |
+
type T struct {
|
| 112 |
+
x E2 "foo"
|
| 113 |
+
}
|
| 114 |
+
var s S
|
| 115 |
+
var t T
|
| 116 |
+
var u struct {
|
| 117 |
+
x E2 "bar"
|
| 118 |
+
}
|
| 119 |
+
s = s
|
| 120 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 121 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 122 |
+
s = S(s)
|
| 123 |
+
s = S(t) // ERROR "cannot convert"
|
| 124 |
+
s = S(u) // ERROR "cannot convert"
|
| 125 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 126 |
+
t = T(u)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
func _() {
|
| 130 |
+
type E struct{ x int }
|
| 131 |
+
type S struct {
|
| 132 |
+
f func(struct {
|
| 133 |
+
x int "foo"
|
| 134 |
+
})
|
| 135 |
+
}
|
| 136 |
+
type T struct {
|
| 137 |
+
f func(struct {
|
| 138 |
+
x int "bar"
|
| 139 |
+
})
|
| 140 |
+
}
|
| 141 |
+
var s S
|
| 142 |
+
var t T
|
| 143 |
+
var u struct{ f func(E) }
|
| 144 |
+
s = s
|
| 145 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 146 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 147 |
+
s = S(s)
|
| 148 |
+
s = S(t)
|
| 149 |
+
s = S(u) // ERROR "cannot convert"
|
| 150 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 151 |
+
t = T(u) // ERROR "cannot convert"
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// conversions between pointers to structs
|
| 155 |
+
|
| 156 |
+
func _() {
|
| 157 |
+
type S struct{}
|
| 158 |
+
type T struct{}
|
| 159 |
+
var s *S
|
| 160 |
+
var t *T
|
| 161 |
+
var u *struct{}
|
| 162 |
+
s = s
|
| 163 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 164 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 165 |
+
s = (*S)(s)
|
| 166 |
+
s = (*S)(t)
|
| 167 |
+
s = (*S)(u)
|
| 168 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 169 |
+
t = (*T)(u)
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func _() {
|
| 173 |
+
type S struct{ x int }
|
| 174 |
+
type T struct {
|
| 175 |
+
x int "foo"
|
| 176 |
+
}
|
| 177 |
+
var s *S
|
| 178 |
+
var t *T
|
| 179 |
+
var u *struct {
|
| 180 |
+
x int "bar"
|
| 181 |
+
}
|
| 182 |
+
s = s
|
| 183 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 184 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 185 |
+
s = (*S)(s)
|
| 186 |
+
s = (*S)(t)
|
| 187 |
+
s = (*S)(u)
|
| 188 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 189 |
+
t = (*T)(u)
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
func _() {
|
| 193 |
+
type E struct{ x int }
|
| 194 |
+
type S struct{ x E }
|
| 195 |
+
type T struct {
|
| 196 |
+
x E "foo"
|
| 197 |
+
}
|
| 198 |
+
var s *S
|
| 199 |
+
var t *T
|
| 200 |
+
var u *struct {
|
| 201 |
+
x E "bar"
|
| 202 |
+
}
|
| 203 |
+
s = s
|
| 204 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 205 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 206 |
+
s = (*S)(s)
|
| 207 |
+
s = (*S)(t)
|
| 208 |
+
s = (*S)(u)
|
| 209 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 210 |
+
t = (*T)(u)
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
func _() {
|
| 214 |
+
type S struct {
|
| 215 |
+
x struct {
|
| 216 |
+
x int "foo"
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
type T struct {
|
| 220 |
+
x struct {
|
| 221 |
+
x int "bar"
|
| 222 |
+
} "foo"
|
| 223 |
+
}
|
| 224 |
+
var s *S
|
| 225 |
+
var t *T
|
| 226 |
+
var u *struct {
|
| 227 |
+
x struct {
|
| 228 |
+
x int "bar"
|
| 229 |
+
} "bar"
|
| 230 |
+
}
|
| 231 |
+
s = s
|
| 232 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 233 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 234 |
+
s = (*S)(s)
|
| 235 |
+
s = (*S)(t)
|
| 236 |
+
s = (*S)(u)
|
| 237 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 238 |
+
t = (*T)(u)
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
func _() {
|
| 242 |
+
type E1 struct {
|
| 243 |
+
x int "foo"
|
| 244 |
+
}
|
| 245 |
+
type E2 struct {
|
| 246 |
+
x int "bar"
|
| 247 |
+
}
|
| 248 |
+
type S struct{ x E1 }
|
| 249 |
+
type T struct {
|
| 250 |
+
x E2 "foo"
|
| 251 |
+
}
|
| 252 |
+
var s *S
|
| 253 |
+
var t *T
|
| 254 |
+
var u *struct {
|
| 255 |
+
x E2 "bar"
|
| 256 |
+
}
|
| 257 |
+
s = s
|
| 258 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 259 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 260 |
+
s = (*S)(s)
|
| 261 |
+
s = (*S)(t) // ERROR "cannot convert"
|
| 262 |
+
s = (*S)(u) // ERROR "cannot convert"
|
| 263 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 264 |
+
t = (*T)(u)
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
func _() {
|
| 268 |
+
type E struct{ x int }
|
| 269 |
+
type S struct {
|
| 270 |
+
f func(struct {
|
| 271 |
+
x int "foo"
|
| 272 |
+
})
|
| 273 |
+
}
|
| 274 |
+
type T struct {
|
| 275 |
+
f func(struct {
|
| 276 |
+
x int "bar"
|
| 277 |
+
})
|
| 278 |
+
}
|
| 279 |
+
var s *S
|
| 280 |
+
var t *T
|
| 281 |
+
var u *struct{ f func(E) }
|
| 282 |
+
s = s
|
| 283 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 284 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 285 |
+
s = (*S)(s)
|
| 286 |
+
s = (*S)(t)
|
| 287 |
+
s = (*S)(u) // ERROR "cannot convert"
|
| 288 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 289 |
+
t = (*T)(u) // ERROR "cannot convert"
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
func _() {
|
| 293 |
+
type E struct{ x int }
|
| 294 |
+
type S struct {
|
| 295 |
+
f func(*struct {
|
| 296 |
+
x int "foo"
|
| 297 |
+
})
|
| 298 |
+
}
|
| 299 |
+
type T struct {
|
| 300 |
+
f func(*struct {
|
| 301 |
+
x int "bar"
|
| 302 |
+
})
|
| 303 |
+
}
|
| 304 |
+
var s *S
|
| 305 |
+
var t *T
|
| 306 |
+
var u *struct{ f func(E) }
|
| 307 |
+
s = s
|
| 308 |
+
s = t // ERROR "cannot use .* in assignment|incompatible type"
|
| 309 |
+
s = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 310 |
+
s = (*S)(s)
|
| 311 |
+
s = (*S)(t)
|
| 312 |
+
s = (*S)(u) // ERROR "cannot convert"
|
| 313 |
+
t = u // ERROR "cannot use .* in assignment|incompatible type"
|
| 314 |
+
t = (*T)(u) // ERROR "cannot convert"
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
func _() {
|
| 318 |
+
var s []byte
|
| 319 |
+
_ = ([4]byte)(s)
|
| 320 |
+
_ = (*[4]byte)(s)
|
| 321 |
+
|
| 322 |
+
type A [4]byte
|
| 323 |
+
_ = (A)(s)
|
| 324 |
+
_ = (*A)(s)
|
| 325 |
+
|
| 326 |
+
type P *[4]byte
|
| 327 |
+
_ = (P)(s)
|
| 328 |
+
_ = (*P)(s) // ERROR "cannot convert"
|
| 329 |
+
}
|
platform/dbops/binaries/go/go/test/convert3.go
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify allowed and disallowed conversions.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
// everything here is legal except the ERROR line
|
| 13 |
+
|
| 14 |
+
var c chan int
|
| 15 |
+
var d1 chan<- int = c
|
| 16 |
+
var d2 = (chan<- int)(c)
|
| 17 |
+
|
| 18 |
+
var e *[4]int
|
| 19 |
+
var f1 []int = e[0:]
|
| 20 |
+
var f2 = []int(e[0:])
|
| 21 |
+
|
| 22 |
+
var g = []int(nil)
|
| 23 |
+
|
| 24 |
+
type H []int
|
| 25 |
+
type J []int
|
| 26 |
+
|
| 27 |
+
var h H
|
| 28 |
+
var j1 J = h // ERROR "compat|illegal|cannot"
|
| 29 |
+
var j2 = J(h)
|
platform/dbops/binaries/go/go/test/convert4.go
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2020 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Test conversion from slice to array pointer.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
func wantPanic(fn func(), s string) {
|
| 12 |
+
defer func() {
|
| 13 |
+
err := recover()
|
| 14 |
+
if err == nil {
|
| 15 |
+
panic("expected panic")
|
| 16 |
+
}
|
| 17 |
+
if got := err.(error).Error(); got != s {
|
| 18 |
+
panic("expected panic " + s + " got " + got)
|
| 19 |
+
}
|
| 20 |
+
}()
|
| 21 |
+
fn()
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
func main() {
|
| 25 |
+
s := make([]byte, 8, 10)
|
| 26 |
+
for i := range s {
|
| 27 |
+
s[i] = byte(i)
|
| 28 |
+
}
|
| 29 |
+
if p := (*[8]byte)(s); &p[0] != &s[0] {
|
| 30 |
+
panic("*[8]byte conversion failed")
|
| 31 |
+
}
|
| 32 |
+
if [8]byte(s) != *(*[8]byte)(s) {
|
| 33 |
+
panic("[8]byte conversion failed")
|
| 34 |
+
}
|
| 35 |
+
wantPanic(
|
| 36 |
+
func() {
|
| 37 |
+
_ = (*[9]byte)(s)
|
| 38 |
+
},
|
| 39 |
+
"runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
|
| 40 |
+
)
|
| 41 |
+
wantPanic(
|
| 42 |
+
func() {
|
| 43 |
+
_ = [9]byte(s)
|
| 44 |
+
},
|
| 45 |
+
"runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
var n []byte
|
| 49 |
+
if p := (*[0]byte)(n); p != nil {
|
| 50 |
+
panic("nil slice converted to *[0]byte should be nil")
|
| 51 |
+
}
|
| 52 |
+
_ = [0]byte(n)
|
| 53 |
+
|
| 54 |
+
z := make([]byte, 0)
|
| 55 |
+
if p := (*[0]byte)(z); p == nil {
|
| 56 |
+
panic("empty slice converted to *[0]byte should be non-nil")
|
| 57 |
+
}
|
| 58 |
+
_ = [0]byte(z)
|
| 59 |
+
|
| 60 |
+
var p *[]byte
|
| 61 |
+
wantPanic(
|
| 62 |
+
func() {
|
| 63 |
+
_ = [0]byte(*p) // evaluating *p should still panic
|
| 64 |
+
},
|
| 65 |
+
"runtime error: invalid memory address or nil pointer dereference",
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
// Test with named types
|
| 69 |
+
type Slice []int
|
| 70 |
+
type Int4 [4]int
|
| 71 |
+
type PInt4 *[4]int
|
| 72 |
+
ii := make(Slice, 4)
|
| 73 |
+
if p := (*Int4)(ii); &p[0] != &ii[0] {
|
| 74 |
+
panic("*Int4 conversion failed")
|
| 75 |
+
}
|
| 76 |
+
if p := PInt4(ii); &p[0] != &ii[0] {
|
| 77 |
+
panic("PInt4 conversion failed")
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// test static variable conversion
|
| 82 |
+
|
| 83 |
+
var (
|
| 84 |
+
ss = make([]string, 10)
|
| 85 |
+
s5 = (*[5]string)(ss)
|
| 86 |
+
s10 = (*[10]string)(ss)
|
| 87 |
+
|
| 88 |
+
ns []string
|
| 89 |
+
ns0 = (*[0]string)(ns)
|
| 90 |
+
|
| 91 |
+
zs = make([]string, 0)
|
| 92 |
+
zs0 = (*[0]string)(zs)
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
func init() {
|
| 96 |
+
if &ss[0] != &s5[0] {
|
| 97 |
+
panic("s5 conversion failed")
|
| 98 |
+
}
|
| 99 |
+
if &ss[0] != &s10[0] {
|
| 100 |
+
panic("s5 conversion failed")
|
| 101 |
+
}
|
| 102 |
+
if ns0 != nil {
|
| 103 |
+
panic("ns0 should be nil")
|
| 104 |
+
}
|
| 105 |
+
if zs0 == nil {
|
| 106 |
+
panic("zs0 should not be nil")
|
| 107 |
+
}
|
| 108 |
+
}
|
platform/dbops/binaries/go/go/test/convinline.go
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// runoutput
|
| 2 |
+
//go:build !wasm
|
| 3 |
+
|
| 4 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 5 |
+
// Use of this source code is governed by a BSD-style
|
| 6 |
+
// license that can be found in the LICENSE file.
|
| 7 |
+
|
| 8 |
+
package main
|
| 9 |
+
|
| 10 |
+
import (
|
| 11 |
+
"bytes"
|
| 12 |
+
"fmt"
|
| 13 |
+
"math"
|
| 14 |
+
"math/bits"
|
| 15 |
+
"os"
|
| 16 |
+
"strconv"
|
| 17 |
+
"strings"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
var types = []string{
|
| 21 |
+
"int",
|
| 22 |
+
"int8",
|
| 23 |
+
"int16",
|
| 24 |
+
"int32",
|
| 25 |
+
"int64",
|
| 26 |
+
"uint",
|
| 27 |
+
"uint8",
|
| 28 |
+
"uint16",
|
| 29 |
+
"uint32",
|
| 30 |
+
"uint64",
|
| 31 |
+
"uintptr",
|
| 32 |
+
"float32",
|
| 33 |
+
"float64",
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func main() {
|
| 37 |
+
var prog bytes.Buffer
|
| 38 |
+
fmt.Fprintf(&prog, "package main\n\n")
|
| 39 |
+
fmt.Fprintf(&prog, "import ( \"fmt\"; \"math\" )\n")
|
| 40 |
+
for _, t1 := range types {
|
| 41 |
+
for _, t2 := range types {
|
| 42 |
+
fmt.Fprintf(&prog, "func %[1]s_to_%[2]s(x %[1]s) %[2]s { return %[2]s(x) }\n", t1, t2)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
var outputs []string
|
| 47 |
+
var exprs []string
|
| 48 |
+
|
| 49 |
+
fmt.Fprintf(&prog, "var (\n")
|
| 50 |
+
for _, t1 := range types {
|
| 51 |
+
var inputs []string
|
| 52 |
+
switch t1 {
|
| 53 |
+
case "int64", "int":
|
| 54 |
+
if t1 == "int64" || bits.UintSize == 64 {
|
| 55 |
+
inputs = append(inputs, "-0x8000_0000_0000_0000", "-0x7fff_ffff_ffff_ffff", "-0x12_3456_7890", "0x12_3456_7890", "0x7fff_ffff_ffff_ffff")
|
| 56 |
+
}
|
| 57 |
+
fallthrough
|
| 58 |
+
case "int32":
|
| 59 |
+
inputs = append(inputs, "-0x8000_0000", "-0x7fff_ffff", "-0x12_3456", "0x12_3456", "0x7fff_ffff")
|
| 60 |
+
fallthrough
|
| 61 |
+
case "int16":
|
| 62 |
+
inputs = append(inputs, "-0x8000", "-0x7fff", "-0x1234", "0x1234", "0x7fff")
|
| 63 |
+
fallthrough
|
| 64 |
+
case "int8":
|
| 65 |
+
inputs = append(inputs, "-0x80", "-0x7f", "-0x12", "-1", "0", "1", "0x12", "0x7f")
|
| 66 |
+
|
| 67 |
+
case "uint64", "uint", "uintptr":
|
| 68 |
+
if t1 == "uint64" || bits.UintSize == 64 {
|
| 69 |
+
inputs = append(inputs, "0x12_3456_7890", "0x7fff_ffff_ffff_ffff", "0x8000_0000_0000_0000", "0xffff_ffff_ffff_ffff")
|
| 70 |
+
}
|
| 71 |
+
fallthrough
|
| 72 |
+
case "uint32":
|
| 73 |
+
inputs = append(inputs, "0x12_3456", "0x7fff_ffff", "0x8000_0000", "0xffff_ffff")
|
| 74 |
+
fallthrough
|
| 75 |
+
case "uint16":
|
| 76 |
+
inputs = append(inputs, "0x1234", "0x7fff", "0x8000", "0xffff")
|
| 77 |
+
fallthrough
|
| 78 |
+
case "uint8":
|
| 79 |
+
inputs = append(inputs, "0", "1", "0x12", "0x7f", "0x80", "0xff")
|
| 80 |
+
|
| 81 |
+
case "float64":
|
| 82 |
+
inputs = append(inputs,
|
| 83 |
+
"-1.79769313486231570814527423731704356798070e+308",
|
| 84 |
+
"-1e300",
|
| 85 |
+
"-1e100",
|
| 86 |
+
"-1e40",
|
| 87 |
+
"-3.5e38",
|
| 88 |
+
"3.5e38",
|
| 89 |
+
"1e40",
|
| 90 |
+
"1e100",
|
| 91 |
+
"1e300",
|
| 92 |
+
"1.79769313486231570814527423731704356798070e+308")
|
| 93 |
+
fallthrough
|
| 94 |
+
case "float32":
|
| 95 |
+
inputs = append(inputs,
|
| 96 |
+
"-3.40282346638528859811704183484516925440e+38",
|
| 97 |
+
"-1e38",
|
| 98 |
+
"-1.5",
|
| 99 |
+
"-1.401298464324817070923729583289916131280e-45",
|
| 100 |
+
"0",
|
| 101 |
+
"1.401298464324817070923729583289916131280e-45",
|
| 102 |
+
"1.5",
|
| 103 |
+
"1e38",
|
| 104 |
+
"3.40282346638528859811704183484516925440e+38")
|
| 105 |
+
}
|
| 106 |
+
for _, t2 := range types {
|
| 107 |
+
for _, x := range inputs {
|
| 108 |
+
code := fmt.Sprintf("%s_to_%s(%s)", t1, t2, x)
|
| 109 |
+
fmt.Fprintf(&prog, "\tv%d = %s\n", len(outputs), code)
|
| 110 |
+
exprs = append(exprs, code)
|
| 111 |
+
outputs = append(outputs, convert(x, t1, t2))
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
fmt.Fprintf(&prog, ")\n\n")
|
| 116 |
+
fmt.Fprintf(&prog, "func main() {\n\tok := true\n")
|
| 117 |
+
for i, out := range outputs {
|
| 118 |
+
fmt.Fprintf(&prog, "\tif v%d != %s { fmt.Println(%q, \"=\", v%d, \"want\", %s); ok = false }\n", i, out, exprs[i], i, out)
|
| 119 |
+
}
|
| 120 |
+
fmt.Fprintf(&prog, "\tif !ok { println(\"FAIL\") }\n")
|
| 121 |
+
fmt.Fprintf(&prog, "}\n")
|
| 122 |
+
|
| 123 |
+
os.Stdout.Write(prog.Bytes())
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
func convert(x, t1, t2 string) string {
|
| 127 |
+
if strings.HasPrefix(t1, "int") {
|
| 128 |
+
v, err := strconv.ParseInt(x, 0, 64)
|
| 129 |
+
if err != nil {
|
| 130 |
+
println(x, t1, t2)
|
| 131 |
+
panic(err)
|
| 132 |
+
}
|
| 133 |
+
return convert1(v, t2)
|
| 134 |
+
}
|
| 135 |
+
if strings.HasPrefix(t1, "uint") {
|
| 136 |
+
v, err := strconv.ParseUint(x, 0, 64)
|
| 137 |
+
if err != nil {
|
| 138 |
+
println(x, t1, t2)
|
| 139 |
+
panic(err)
|
| 140 |
+
}
|
| 141 |
+
return convert1(v, t2)
|
| 142 |
+
}
|
| 143 |
+
if strings.HasPrefix(t1, "float") {
|
| 144 |
+
v, err := strconv.ParseFloat(x, 64)
|
| 145 |
+
if err != nil {
|
| 146 |
+
println(x, t1, t2)
|
| 147 |
+
panic(err)
|
| 148 |
+
}
|
| 149 |
+
if t1 == "float32" {
|
| 150 |
+
v = float64(float32(v))
|
| 151 |
+
}
|
| 152 |
+
return convert1(v, t2)
|
| 153 |
+
}
|
| 154 |
+
panic(t1)
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
func convert1[T int64 | uint64 | float64](v T, t2 string) string {
|
| 158 |
+
switch t2 {
|
| 159 |
+
case "int":
|
| 160 |
+
return fmt.Sprintf("%s(%#x)", t2, int(v))
|
| 161 |
+
case "int8":
|
| 162 |
+
return fmt.Sprintf("%s(%#x)", t2, int8(v))
|
| 163 |
+
case "int16":
|
| 164 |
+
return fmt.Sprintf("%s(%#x)", t2, int16(v))
|
| 165 |
+
case "int32":
|
| 166 |
+
return fmt.Sprintf("%s(%#x)", t2, int32(v))
|
| 167 |
+
case "int64":
|
| 168 |
+
return fmt.Sprintf("%s(%#x)", t2, int64(v))
|
| 169 |
+
case "uint":
|
| 170 |
+
return fmt.Sprintf("%s(%#x)", t2, uint(v))
|
| 171 |
+
case "uint8":
|
| 172 |
+
return fmt.Sprintf("%s(%#x)", t2, uint8(v))
|
| 173 |
+
case "uint16":
|
| 174 |
+
return fmt.Sprintf("%s(%#x)", t2, uint16(v))
|
| 175 |
+
case "uint32":
|
| 176 |
+
return fmt.Sprintf("%s(%#x)", t2, uint32(v))
|
| 177 |
+
case "uint64":
|
| 178 |
+
return fmt.Sprintf("%s(%#x)", t2, uint64(v))
|
| 179 |
+
case "uintptr":
|
| 180 |
+
return fmt.Sprintf("%s(%#x)", t2, uintptr(v))
|
| 181 |
+
case "float32":
|
| 182 |
+
v := float32(v)
|
| 183 |
+
if math.IsInf(float64(v), -1) {
|
| 184 |
+
return "float32(math.Inf(-1))"
|
| 185 |
+
}
|
| 186 |
+
if math.IsInf(float64(v), +1) {
|
| 187 |
+
return "float32(math.Inf(+1))"
|
| 188 |
+
}
|
| 189 |
+
return fmt.Sprintf("%s(%v)", t2, float64(v))
|
| 190 |
+
case "float64":
|
| 191 |
+
return fmt.Sprintf("%s(%v)", t2, float64(v))
|
| 192 |
+
}
|
| 193 |
+
panic(t2)
|
| 194 |
+
}
|
platform/dbops/binaries/go/go/test/convlit.go
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that illegal assignments with both explicit and implicit conversions of literals are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
import "unsafe"
|
| 13 |
+
|
| 14 |
+
// explicit conversion of constants
|
| 15 |
+
var x1 = string(1)
|
| 16 |
+
var x2 string = string(1)
|
| 17 |
+
var x3 = int(1.5) // ERROR "convert|truncate"
|
| 18 |
+
var x4 int = int(1.5) // ERROR "convert|truncate"
|
| 19 |
+
var x5 = "a" + string(1)
|
| 20 |
+
var x6 = int(1e100) // ERROR "overflow|cannot convert"
|
| 21 |
+
var x7 = float32(1e1000) // ERROR "overflow|cannot convert"
|
| 22 |
+
|
| 23 |
+
// unsafe.Pointer can only convert to/from uintptr
|
| 24 |
+
var _ = string(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion"
|
| 25 |
+
var _ = float64(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion"
|
| 26 |
+
var _ = int(unsafe.Pointer(uintptr(65))) // ERROR "convert|conversion"
|
| 27 |
+
|
| 28 |
+
// implicit conversions merit scrutiny
|
| 29 |
+
var s string
|
| 30 |
+
var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot"
|
| 31 |
+
var bad2 = s + 1 // ERROR "conver|incompatible|invalid|cannot"
|
| 32 |
+
var bad3 = s + 'a' // ERROR "conver|incompatible|invalid|cannot"
|
| 33 |
+
var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid"
|
| 34 |
+
var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid"
|
| 35 |
+
|
| 36 |
+
var bad6 int = 1.5 // ERROR "convert|truncate"
|
| 37 |
+
var bad7 int = 1e100 // ERROR "overflow|truncated to int|truncated"
|
| 38 |
+
var bad8 float32 = 1e200 // ERROR "overflow"
|
| 39 |
+
|
| 40 |
+
// but these implicit conversions are okay
|
| 41 |
+
var good1 string = "a"
|
| 42 |
+
var good2 int = 1.0
|
| 43 |
+
var good3 int = 1e9
|
| 44 |
+
var good4 float64 = 1e20
|
| 45 |
+
|
| 46 |
+
// explicit conversion of string is okay
|
| 47 |
+
var _ = []rune("abc")
|
| 48 |
+
var _ = []byte("abc")
|
| 49 |
+
|
| 50 |
+
// implicit is not
|
| 51 |
+
var _ []int = "abc" // ERROR "cannot use|incompatible|invalid|cannot convert"
|
| 52 |
+
var _ []byte = "abc" // ERROR "cannot use|incompatible|invalid|cannot convert"
|
| 53 |
+
|
| 54 |
+
// named string is okay
|
| 55 |
+
type Tstring string
|
| 56 |
+
|
| 57 |
+
var ss Tstring = "abc"
|
| 58 |
+
var _ = []rune(ss)
|
| 59 |
+
var _ = []byte(ss)
|
| 60 |
+
|
| 61 |
+
// implicit is still not
|
| 62 |
+
var _ []rune = ss // ERROR "cannot use|incompatible|invalid"
|
| 63 |
+
var _ []byte = ss // ERROR "cannot use|incompatible|invalid"
|
| 64 |
+
|
| 65 |
+
// named slice is now ok
|
| 66 |
+
type Trune []rune
|
| 67 |
+
type Tbyte []byte
|
| 68 |
+
|
| 69 |
+
var _ = Trune("abc") // ok
|
| 70 |
+
var _ = Tbyte("abc") // ok
|
| 71 |
+
|
| 72 |
+
// implicit is still not
|
| 73 |
+
var _ Trune = "abc" // ERROR "cannot use|incompatible|invalid|cannot convert"
|
| 74 |
+
var _ Tbyte = "abc" // ERROR "cannot use|incompatible|invalid|cannot convert"
|
platform/dbops/binaries/go/go/test/convlit1.go
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// errorcheck
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Verify that illegal uses of composite literals are detected.
|
| 8 |
+
// Does not compile.
|
| 9 |
+
|
| 10 |
+
package main
|
| 11 |
+
|
| 12 |
+
var a = []int { "a" }; // ERROR "conver|incompatible|cannot"
|
| 13 |
+
var b = int { 1 }; // ERROR "compos"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
func f() int
|
| 17 |
+
|
| 18 |
+
func main() {
|
| 19 |
+
if f < 1 { } // ERROR "conver|incompatible|invalid"
|
| 20 |
+
}
|
platform/dbops/binaries/go/go/test/copy.go
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// run
|
| 2 |
+
|
| 3 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 4 |
+
// Use of this source code is governed by a BSD-style
|
| 5 |
+
// license that can be found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
// Semi-exhaustive test for the copy predeclared function.
|
| 8 |
+
|
| 9 |
+
package main
|
| 10 |
+
|
| 11 |
+
import (
|
| 12 |
+
"fmt"
|
| 13 |
+
"os"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
const N = 40
|
| 17 |
+
|
| 18 |
+
var input8 = make([]uint8, N)
|
| 19 |
+
var output8 = make([]uint8, N)
|
| 20 |
+
var input16 = make([]uint16, N)
|
| 21 |
+
var output16 = make([]uint16, N)
|
| 22 |
+
var input32 = make([]uint32, N)
|
| 23 |
+
var output32 = make([]uint32, N)
|
| 24 |
+
var input64 = make([]uint64, N)
|
| 25 |
+
var output64 = make([]uint64, N)
|
| 26 |
+
var inputS string
|
| 27 |
+
var outputS = make([]uint8, N)
|
| 28 |
+
|
| 29 |
+
type my8 []uint8
|
| 30 |
+
type my16 []uint16
|
| 31 |
+
type my32 []uint32
|
| 32 |
+
type my32b []uint32
|
| 33 |
+
type my64 []uint64
|
| 34 |
+
type myS string
|
| 35 |
+
|
| 36 |
+
func u8(i int) uint8 {
|
| 37 |
+
i = 'a' + i%26
|
| 38 |
+
return uint8(i)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func u16(ii int) uint16 {
|
| 42 |
+
var i = uint16(ii)
|
| 43 |
+
i = 'a' + i%26
|
| 44 |
+
i |= i << 8
|
| 45 |
+
return i
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func u32(ii int) uint32 {
|
| 49 |
+
var i = uint32(ii)
|
| 50 |
+
i = 'a' + i%26
|
| 51 |
+
i |= i << 8
|
| 52 |
+
i |= i << 16
|
| 53 |
+
return i
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func u64(ii int) uint64 {
|
| 57 |
+
var i = uint64(ii)
|
| 58 |
+
i = 'a' + i%26
|
| 59 |
+
i |= i << 8
|
| 60 |
+
i |= i << 16
|
| 61 |
+
i |= i << 32
|
| 62 |
+
return i
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func reset() {
|
| 66 |
+
// swap in and out to exercise copy-up and copy-down
|
| 67 |
+
input8, output8 = output8, input8
|
| 68 |
+
input16, output16 = output16, input16
|
| 69 |
+
input32, output32 = output32, input32
|
| 70 |
+
input64, output64 = output64, input64
|
| 71 |
+
in := 0
|
| 72 |
+
out := 13
|
| 73 |
+
for i := range input8 {
|
| 74 |
+
input8[i] = u8(in)
|
| 75 |
+
output8[i] = u8(out)
|
| 76 |
+
outputS[i] = u8(out)
|
| 77 |
+
input16[i] = u16(in)
|
| 78 |
+
output16[i] = u16(out)
|
| 79 |
+
input32[i] = u32(in)
|
| 80 |
+
output32[i] = u32(out)
|
| 81 |
+
input64[i] = u64(in)
|
| 82 |
+
output64[i] = u64(out)
|
| 83 |
+
in++
|
| 84 |
+
out++
|
| 85 |
+
}
|
| 86 |
+
inputS = string(input8)
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
func clamp(n int) int {
|
| 90 |
+
if n > N {
|
| 91 |
+
return N
|
| 92 |
+
}
|
| 93 |
+
return n
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
func ncopied(length, in, out int) int {
|
| 97 |
+
n := length
|
| 98 |
+
if in+n > N {
|
| 99 |
+
n = N - in
|
| 100 |
+
}
|
| 101 |
+
if out+n > N {
|
| 102 |
+
n = N - out
|
| 103 |
+
}
|
| 104 |
+
return n
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
func doAllSlices(length, in, out int) {
|
| 108 |
+
reset()
|
| 109 |
+
n := copy(my8(output8[out:clamp(out+length)]), input8[in:clamp(in+length)])
|
| 110 |
+
verify8(length, in, out, n)
|
| 111 |
+
n = copy(my8(outputS[out:clamp(out+length)]), myS(inputS[in:clamp(in+length)]))
|
| 112 |
+
verifyS(length, in, out, n)
|
| 113 |
+
n = copy(my16(output16[out:clamp(out+length)]), input16[in:clamp(in+length)])
|
| 114 |
+
verify16(length, in, out, n)
|
| 115 |
+
n = copy(my32(output32[out:clamp(out+length)]), my32b(input32[in:clamp(in+length)]))
|
| 116 |
+
verify32(length, in, out, n)
|
| 117 |
+
n = copy(my64(output64[out:clamp(out+length)]), input64[in:clamp(in+length)])
|
| 118 |
+
verify64(length, in, out, n)
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
func bad8(state string, i, length, in, out int) {
|
| 122 |
+
fmt.Printf("%s bad(%d %d %d): %c not %c:\n\t%s\n\t%s\n",
|
| 123 |
+
state,
|
| 124 |
+
length, in, out,
|
| 125 |
+
output8[i],
|
| 126 |
+
uint8(i+13),
|
| 127 |
+
input8, output8)
|
| 128 |
+
os.Exit(1)
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
func verify8(length, in, out, m int) {
|
| 132 |
+
n := ncopied(length, in, out)
|
| 133 |
+
if m != n {
|
| 134 |
+
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
| 135 |
+
os.Exit(1)
|
| 136 |
+
return
|
| 137 |
+
}
|
| 138 |
+
// before
|
| 139 |
+
var i int
|
| 140 |
+
for i = 0; i < out; i++ {
|
| 141 |
+
if output8[i] != u8(i+13) {
|
| 142 |
+
bad8("before8", i, length, in, out)
|
| 143 |
+
return
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
// copied part
|
| 147 |
+
for ; i < out+n; i++ {
|
| 148 |
+
if output8[i] != u8(i+in-out) {
|
| 149 |
+
bad8("copied8", i, length, in, out)
|
| 150 |
+
return
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
// after
|
| 154 |
+
for ; i < len(output8); i++ {
|
| 155 |
+
if output8[i] != u8(i+13) {
|
| 156 |
+
bad8("after8", i, length, in, out)
|
| 157 |
+
return
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
func badS(state string, i, length, in, out int) {
|
| 163 |
+
fmt.Printf("%s bad(%d %d %d): %c not %c:\n\t%s\n\t%s\n",
|
| 164 |
+
state,
|
| 165 |
+
length, in, out,
|
| 166 |
+
outputS[i],
|
| 167 |
+
uint8(i+13),
|
| 168 |
+
inputS, outputS)
|
| 169 |
+
os.Exit(1)
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func verifyS(length, in, out, m int) {
|
| 173 |
+
n := ncopied(length, in, out)
|
| 174 |
+
if m != n {
|
| 175 |
+
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
| 176 |
+
os.Exit(1)
|
| 177 |
+
return
|
| 178 |
+
}
|
| 179 |
+
// before
|
| 180 |
+
var i int
|
| 181 |
+
for i = 0; i < out; i++ {
|
| 182 |
+
if outputS[i] != u8(i+13) {
|
| 183 |
+
badS("beforeS", i, length, in, out)
|
| 184 |
+
return
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
// copied part
|
| 188 |
+
for ; i < out+n; i++ {
|
| 189 |
+
if outputS[i] != u8(i+in-out) {
|
| 190 |
+
badS("copiedS", i, length, in, out)
|
| 191 |
+
return
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
// after
|
| 195 |
+
for ; i < len(outputS); i++ {
|
| 196 |
+
if outputS[i] != u8(i+13) {
|
| 197 |
+
badS("afterS", i, length, in, out)
|
| 198 |
+
return
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
func bad16(state string, i, length, in, out int) {
|
| 204 |
+
fmt.Printf("%s bad(%d %d %d): %x not %x:\n\t%v\n\t%v\n",
|
| 205 |
+
state,
|
| 206 |
+
length, in, out,
|
| 207 |
+
output16[i],
|
| 208 |
+
uint16(i+13),
|
| 209 |
+
input16, output16)
|
| 210 |
+
os.Exit(1)
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
func verify16(length, in, out, m int) {
|
| 214 |
+
n := ncopied(length, in, out)
|
| 215 |
+
if m != n {
|
| 216 |
+
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
| 217 |
+
os.Exit(1)
|
| 218 |
+
return
|
| 219 |
+
}
|
| 220 |
+
// before
|
| 221 |
+
var i int
|
| 222 |
+
for i = 0; i < out; i++ {
|
| 223 |
+
if output16[i] != u16(i+13) {
|
| 224 |
+
bad16("before16", i, length, in, out)
|
| 225 |
+
return
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
// copied part
|
| 229 |
+
for ; i < out+n; i++ {
|
| 230 |
+
if output16[i] != u16(i+in-out) {
|
| 231 |
+
bad16("copied16", i, length, in, out)
|
| 232 |
+
return
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
// after
|
| 236 |
+
for ; i < len(output16); i++ {
|
| 237 |
+
if output16[i] != u16(i+13) {
|
| 238 |
+
bad16("after16", i, length, in, out)
|
| 239 |
+
return
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
func bad32(state string, i, length, in, out int) {
|
| 245 |
+
fmt.Printf("%s bad(%d %d %d): %x not %x:\n\t%v\n\t%v\n",
|
| 246 |
+
state,
|
| 247 |
+
length, in, out,
|
| 248 |
+
output32[i],
|
| 249 |
+
uint32(i+13),
|
| 250 |
+
input32, output32)
|
| 251 |
+
os.Exit(1)
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
func verify32(length, in, out, m int) {
|
| 255 |
+
n := ncopied(length, in, out)
|
| 256 |
+
if m != n {
|
| 257 |
+
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
| 258 |
+
os.Exit(1)
|
| 259 |
+
return
|
| 260 |
+
}
|
| 261 |
+
// before
|
| 262 |
+
var i int
|
| 263 |
+
for i = 0; i < out; i++ {
|
| 264 |
+
if output32[i] != u32(i+13) {
|
| 265 |
+
bad32("before32", i, length, in, out)
|
| 266 |
+
return
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
// copied part
|
| 270 |
+
for ; i < out+n; i++ {
|
| 271 |
+
if output32[i] != u32(i+in-out) {
|
| 272 |
+
bad32("copied32", i, length, in, out)
|
| 273 |
+
return
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
// after
|
| 277 |
+
for ; i < len(output32); i++ {
|
| 278 |
+
if output32[i] != u32(i+13) {
|
| 279 |
+
bad32("after32", i, length, in, out)
|
| 280 |
+
return
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
func bad64(state string, i, length, in, out int) {
|
| 286 |
+
fmt.Printf("%s bad(%d %d %d): %x not %x:\n\t%v\n\t%v\n",
|
| 287 |
+
state,
|
| 288 |
+
length, in, out,
|
| 289 |
+
output64[i],
|
| 290 |
+
uint64(i+13),
|
| 291 |
+
input64, output64)
|
| 292 |
+
os.Exit(1)
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
func verify64(length, in, out, m int) {
|
| 296 |
+
n := ncopied(length, in, out)
|
| 297 |
+
if m != n {
|
| 298 |
+
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
| 299 |
+
os.Exit(1)
|
| 300 |
+
return
|
| 301 |
+
}
|
| 302 |
+
// before
|
| 303 |
+
var i int
|
| 304 |
+
for i = 0; i < out; i++ {
|
| 305 |
+
if output64[i] != u64(i+13) {
|
| 306 |
+
bad64("before64", i, length, in, out)
|
| 307 |
+
return
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
// copied part
|
| 311 |
+
for ; i < out+n; i++ {
|
| 312 |
+
if output64[i] != u64(i+in-out) {
|
| 313 |
+
bad64("copied64", i, length, in, out)
|
| 314 |
+
return
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
// after
|
| 318 |
+
for ; i < len(output64); i++ {
|
| 319 |
+
if output64[i] != u64(i+13) {
|
| 320 |
+
bad64("after64", i, length, in, out)
|
| 321 |
+
return
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
func slice() {
|
| 327 |
+
for length := 0; length < N; length++ {
|
| 328 |
+
for in := 0; in <= 32; in++ {
|
| 329 |
+
for out := 0; out <= 32; out++ {
|
| 330 |
+
doAllSlices(length, in, out)
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
// Array test. Can be much simpler. It's only checking for correct handling of [0:].
|
| 337 |
+
func array() {
|
| 338 |
+
var array [N]uint8
|
| 339 |
+
reset()
|
| 340 |
+
copy(array[0:], input8)
|
| 341 |
+
for i := 0; i < N; i++ {
|
| 342 |
+
output8[i] = 0
|
| 343 |
+
}
|
| 344 |
+
copy(output8, array[0:])
|
| 345 |
+
verify8(N, 0, 0, N)
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
func main() {
|
| 349 |
+
slice()
|
| 350 |
+
array()
|
| 351 |
+
}
|