diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/main.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..175a09c7799734082fe0c69d704d40558f1eb952 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/main.go @@ -0,0 +1,32 @@ +// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out + +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main +func main() { +F1() +F2() +F3() +F4() +F5() +F6() +F7() +F8() +F9() +F10() +F11() +F12() +F13() +F14() +F15() +F16() +F17() +F18() +F19() +F20() +} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z1.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z1.go new file mode 100644 index 0000000000000000000000000000000000000000..7f163e9a1d97c4f3fb1afd4f3bd57f8415e95b8a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z1.go @@ -0,0 +1,5 @@ + + +//line x1.go:4 +package main +func F1() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z10.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z10.go new file mode 100644 index 0000000000000000000000000000000000000000..19c70020e0ca367624a97a47be7256aebee1f32b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z10.go @@ -0,0 +1,6 @@ + + + +//line x10.go:4 +package main +func F10() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z11.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z11.go new file mode 100644 index 0000000000000000000000000000000000000000..c1d2f9180f11752e79734507a7d041d193c80903 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z11.go @@ -0,0 +1,4 @@ + +//line x11.go:4 +package main +func F11() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z12.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z12.go new file mode 100644 index 0000000000000000000000000000000000000000..7455f18946826965937e88b17cf613e9802f410d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z12.go @@ -0,0 +1,4 @@ + +//line x12.go:4 +package main +func F12() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z13.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z13.go new file mode 100644 index 0000000000000000000000000000000000000000..ecb3c4c8c711dba7e20d8fdfaba1f47389a4c720 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z13.go @@ -0,0 +1,4 @@ + +//line x13.go:4 +package main +func F13() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z14.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z14.go new file mode 100644 index 0000000000000000000000000000000000000000..134b39b64e2bda6b4bf3fd9da6c4419590546971 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z14.go @@ -0,0 +1,4 @@ + +//line x14.go:4 +package main +func F14() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z15.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z15.go new file mode 100644 index 0000000000000000000000000000000000000000..d73819b443ba1b7734261eb0fc9ec7e262022c1f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z15.go @@ -0,0 +1,4 @@ + +//line x15.go:4 +package main +func F15() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z16.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z16.go new file mode 100644 index 0000000000000000000000000000000000000000..6c31651baa891e4ebff5e8a061e05a060fd336f3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z16.go @@ -0,0 +1,4 @@ + +//line x16.go:4 +package main +func F16() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z17.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z17.go new file mode 100644 index 0000000000000000000000000000000000000000..b742d1672606cabc4b9fc31cdb3e039f69481186 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z17.go @@ -0,0 +1,4 @@ + +//line x17.go:4 +package main +func F17() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z18.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z18.go new file mode 100644 index 0000000000000000000000000000000000000000..84150ff0a35569ddbdcc45021f3200f377443324 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z18.go @@ -0,0 +1,5 @@ + + +//line x18.go:4 +package main +func F18() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z19.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z19.go new file mode 100644 index 0000000000000000000000000000000000000000..bb2e29684174f20a92926ec988ba9daad1f3d47b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z19.go @@ -0,0 +1,4 @@ + +//line x19.go:4 +package main +func F19() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z2.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z2.go new file mode 100644 index 0000000000000000000000000000000000000000..68bd58257d9a025d26459c9f471278fd6a131e18 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z2.go @@ -0,0 +1,4 @@ + +//line x2.go:4 +package main +func F2() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z20.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z20.go new file mode 100644 index 0000000000000000000000000000000000000000..03111e184521d6a5535cc22ca60d42cfef73ca3c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z20.go @@ -0,0 +1,4 @@ + +//line x20.go:4 +package main +func F20() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z3.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z3.go new file mode 100644 index 0000000000000000000000000000000000000000..5e4ad3ae257df2bdbeaee6e382005121e049188d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z3.go @@ -0,0 +1,4 @@ + +//line x3.go:4 +package main +func F3() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z4.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z4.go new file mode 100644 index 0000000000000000000000000000000000000000..1f28465c57714f35f4dbac9b173f32a5b424fa26 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z4.go @@ -0,0 +1,4 @@ + +//line x4.go:4 +package main +func F4() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z5.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z5.go new file mode 100644 index 0000000000000000000000000000000000000000..7f4eeb419a35bcec5bdb83f1b767a4032df4570e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z5.go @@ -0,0 +1,4 @@ + +//line x5.go:4 +package main +func F5() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z6.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z6.go new file mode 100644 index 0000000000000000000000000000000000000000..241791dff2b0e003fa592d70e4752689e51e81ef --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z6.go @@ -0,0 +1,4 @@ + +//line x6.go:4 +package main +func F6() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z7.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z7.go new file mode 100644 index 0000000000000000000000000000000000000000..68c1ad0c2434ad098addca086e34a88998456372 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z7.go @@ -0,0 +1,4 @@ + +//line x7.go:4 +package main +func F7() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z8.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z8.go new file mode 100644 index 0000000000000000000000000000000000000000..16eed32a28d3c4bcca08507f31ff5e3508f68438 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z8.go @@ -0,0 +1,4 @@ + +//line x8.go:4 +package main +func F8() {} diff --git a/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z9.go b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z9.go new file mode 100644 index 0000000000000000000000000000000000000000..cbb94b4d2beddef80e39ec29177b561725c920a3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/dwarf/dwarf.dir/z9.go @@ -0,0 +1,4 @@ + +//line x9.go:4 +package main +func F9() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug0.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug0.go new file mode 100644 index 0000000000000000000000000000000000000000..2f59d81a614d4857ec61f5e786a2e1f0a544bfb4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug0.go @@ -0,0 +1,10 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug0 + +type t0 struct { +} + +var V0 t0 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug1.go new file mode 100644 index 0000000000000000000000000000000000000000..ea5bcfe205ad5da6f954bd31cdc317537f8ab457 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug083.dir/bug1.go @@ -0,0 +1,14 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug1 + +import "./bug0" + +// This is expected to fail--t0 is in package bug0 and should not be +// visible here in package bug1. The test for failure is in +// ../bug083.go. + +var v1 bug0.t0; // ERROR "bug0" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug0.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug0.go new file mode 100644 index 0000000000000000000000000000000000000000..7a6e34747f6605013de116965fbbfb8146b21a79 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug0.go @@ -0,0 +1,9 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug0 + +var V0 func() int; +var V1 func() (a int); +var V2 func() (a, b int); diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug1.go new file mode 100644 index 0000000000000000000000000000000000000000..2568e37d0209cef4ac690c094c2c2559298fff53 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug088.dir/bug1.go @@ -0,0 +1,23 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import P "./bug0" + +func main() { + a0 := P.V0(); // works + a1 := P.V1(); // works + a2, b2 := P.V2(); // doesn't work + _, _, _, _ = a0, a1, a2, b2; +} + +/* +uetli:~/Source/go1/test/bugs/bug088.dir gri$ 6g bug0.go && 6g bug1.go +bug1.go:8: shape error across := +bug1.go:8: a2: undefined +bug1.go:8: b2: undefined +bug1.go:8: illegal types for operand: AS + (<(bug0)P.int32>INT32) +*/ diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug0.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug0.go new file mode 100644 index 0000000000000000000000000000000000000000..7494c580b77df90b611f873c52e4f3431aae6967 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug0.go @@ -0,0 +1,7 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug0 + +const A = -1 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug1.go new file mode 100644 index 0000000000000000000000000000000000000000..eff0d36ed29532d38db96962fa511d18e9f10f93 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug106.dir/bug1.go @@ -0,0 +1,8 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug1 + +import _ "./bug0" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug0.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug0.go new file mode 100644 index 0000000000000000000000000000000000000000..19a2bfbd4b545214ecd153ea7e7cf12c3a3f76a1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug0.go @@ -0,0 +1,7 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug0 + +type T struct { i int } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug1.go new file mode 100644 index 0000000000000000000000000000000000000000..dd59b2f2ec193b58a436c20f501c69c48e599c72 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug1.go @@ -0,0 +1,9 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug1 + +import "./bug0" + +type T struct { t bug0.T } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug2.go new file mode 100644 index 0000000000000000000000000000000000000000..b6184c2e75b03e047441741e301690f16399a03a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug133.dir/bug2.go @@ -0,0 +1,16 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bug2 + +import _ "./bug1" +import "./bug0" + +type T2 struct { t bug0.T } + +func fn(p *T2) int { + // This reference should be invalid, because bug0.T.i is local + // to package bug0 and should not be visible in package bug1. + return p.t.i; // ERROR "field|undef" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/x.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/x.go new file mode 100644 index 0000000000000000000000000000000000000000..2673552d80b8a6a2a6286ff79dc01987d2772ca9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/x.go @@ -0,0 +1,8 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package x + +const Zero = 0.0 +const Ten = 10.0 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/y.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/y.go new file mode 100644 index 0000000000000000000000000000000000000000..428808dd19879a0a56ce39b90a60363a19c914f4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug160.dir/y.go @@ -0,0 +1,19 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "os" +import "./x" + +func main() { + if x.Zero != 0 { + println("x.Zero = ", x.Zero); + os.Exit(1); + } + if x.Ten != 10 { + println("x.Ten = ", x.Ten); + os.Exit(1); + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..139a8a3a2307d0814548dc16ba0a908e3a280e19 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/a.go @@ -0,0 +1,14 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +var A int + +func init() { + A = 1 +} + +type T int; + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..36770f6fc99e3f814ec16dd13d4d2f305a81dc98 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/b.go @@ -0,0 +1,13 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +var B int + +func init() { + B = 2 +} + +type V int; diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..2d24dd12d5293d97e7891dd52493e2e393e8cc68 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug191.dir/main.go @@ -0,0 +1,17 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import . "./a" +import . "./b" + +var _ T +var _ V + +func main() { + if A != 1 || B != 2 { + panic("wrong vars") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug.go new file mode 100644 index 0000000000000000000000000000000000000000..16920246e00d2056e7978efbb73f1db77848de09 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug.go @@ -0,0 +1,9 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package chanbug +var C chan<- (chan int) +var D chan<- func() +var E func() chan int +var F func() (func()) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug2.go new file mode 100644 index 0000000000000000000000000000000000000000..b6c416f83458d71b9930d05211ca712f66d034d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug222.dir/chanbug2.go @@ -0,0 +1,7 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package Bar + +import _ "./chanbug" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug0.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug0.go new file mode 100644 index 0000000000000000000000000000000000000000..78433f504d322f0d786a8dbd2a7a72ab08d91c70 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug0.go @@ -0,0 +1,13 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package p + +type T struct { + X, Y int +} + +type I interface { + M(T) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug1.go new file mode 100644 index 0000000000000000000000000000000000000000..f1db77d2f5d31976a2af3c395e0e158f81400fdc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug1.go @@ -0,0 +1,13 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package q + +type T struct { + X, Y int +} + +type I interface { + M(T) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug2.go new file mode 100644 index 0000000000000000000000000000000000000000..92a7974679eae10349fe8f4f7817cbf39fbf28dd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug2.go @@ -0,0 +1,73 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package s + +import ( + p0 "./bug0" + p1 "./bug1" +) + +// both p0.T and p1.T are struct { X, Y int }. + +var v0 p0.T +var v1 p1.T + +// interfaces involving the two + +type I0 interface { + M(p0.T) +} + +type I1 interface { + M(p1.T) +} + +// t0 satisfies I0 and p0.I +type t0 int + +func (t0) M(p0.T) {} + +// t1 satisfies I1 and p1.I +type t1 float64 + +func (t1) M(p1.T) {} + +// check static interface assignments +var i0 I0 = t0(0) // ok +var i1 I1 = t1(0) // ok + +var i2 I0 = t1(0) // ERROR "does not implement|incompatible" +var i3 I1 = t0(0) // ERROR "does not implement|incompatible" + +var p0i p0.I = t0(0) // ok +var p1i p1.I = t1(0) // ok + +var p0i1 p0.I = t1(0) // ERROR "does not implement|incompatible" +var p0i2 p1.I = t0(0) // ERROR "does not implement|incompatible" + +func foobar() { + // check that cannot assign one to the other, + // but can convert. + v0 = v1 // ERROR "assign|cannot use" + v1 = v0 // ERROR "assign|cannot use" + + v0 = p0.T(v1) + v1 = p1.T(v0) + + i0 = i1 // ERROR "cannot use|incompatible" + i1 = i0 // ERROR "cannot use|incompatible" + p0i = i1 // ERROR "cannot use|incompatible" + p1i = i0 // ERROR "cannot use|incompatible" + i0 = p1i // ERROR "cannot use|incompatible" + i1 = p0i // ERROR "cannot use|incompatible" + p0i = p1i // ERROR "cannot use|incompatible" + p1i = p0i // ERROR "cannot use|incompatible" + + i0 = p0i + p0i = i0 + + i1 = p1i + p1i = i1 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug3.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug3.go new file mode 100644 index 0000000000000000000000000000000000000000..ba547d64a1074fd63facf0d7416a4284ffcfd40f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug248.dir/bug3.go @@ -0,0 +1,105 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package main + +import ( + p0 "./bug0" + p1 "./bug1" + + "reflect" + "strings" +) + +var v0 p0.T +var v1 p1.T + +type I0 interface { + M(p0.T) +} + +type I1 interface { + M(p1.T) +} + +type t0 int + +func (t0) M(p0.T) {} + +type t1 float64 + +func (t1) M(p1.T) {} + +var i0 I0 = t0(0) // ok +var i1 I1 = t1(0) // ok + +var p0i p0.I = t0(0) // ok +var p1i p1.I = t1(0) // ok + +func main() { + // check that reflect paths are correct, + // meaning that reflect data for v0, v1 didn't get confused. + + // path is full (rooted) path name. check suffix for gc, prefix for gccgo + if s := reflect.TypeOf(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") { + println("bad v0 path", len(s), s) + panic("fail") + } + if s := reflect.TypeOf(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") { + println("bad v1 path", s) + panic("fail") + } + + // check that dynamic interface check doesn't get confused + var i interface{} = t0(0) + if _, ok := i.(I1); ok { + println("used t0 as i1") + panic("fail") + } + if _, ok := i.(p1.I); ok { + println("used t0 as p1.I") + panic("fail") + } + + i = t1(1) + if _, ok := i.(I0); ok { + println("used t1 as i0") + panic("fail") + } + if _, ok := i.(p0.I); ok { + println("used t1 as p0.I") + panic("fail") + } + + // check that type switch works. + // the worry is that if p0.T and p1.T have the same hash, + // the binary search will handle one of them incorrectly. + for j := 0; j < 3; j++ { + switch j { + case 0: + i = p0.T{} + case 1: + i = p1.T{} + case 2: + i = 3.14 + } + switch i.(type) { + case p0.T: + if j != 0 { + println("type switch p0.T") + panic("fail") + } + case p1.T: + if j != 1 { + println("type switch p1.T") + panic("fail") + } + default: + if j != 2 { + println("type switch default", j) + panic("fail") + } + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..0f7422c0ba0e2d68c30a28e4c702785daa2523f5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p1.go @@ -0,0 +1,10 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +type T struct { + f func() "x" +} + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p2.go new file mode 100644 index 0000000000000000000000000000000000000000..f614507946602c75adfc1d76ba41b1908c7b9da7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug282.dir/p2.go @@ -0,0 +1,8 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p2 + +import _ "./p1" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..b28551807d663b885f3ff0e167651869367be5c3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p1.go @@ -0,0 +1,9 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +type T <-chan int +var x = make(chan T) + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p2.go new file mode 100644 index 0000000000000000000000000000000000000000..f614507946602c75adfc1d76ba41b1908c7b9da7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug306.dir/p2.go @@ -0,0 +1,8 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p2 + +import _ "./p1" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..335f84d4ba16b2e1fa2ae0c178429289ef991801 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/a.go @@ -0,0 +1,11 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func a() { + fmt.DoesNotExist() // ERROR "undefined" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..26e6413702fc3bcbff42d2765aeaa2c08783d88d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug313.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import . "fmt" + +func b() { + Println() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/lib.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/lib.go new file mode 100644 index 0000000000000000000000000000000000000000..0de56d3d649354e5196e2b2af18f520516083149 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/lib.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package lib + +type T struct { + x int // non-exported field +} + +func (t T) M() { +} + +func (t *T) PM() { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..f403c7d32e2ac187a054100c679d97aa1c73a851 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug322.dir/main.go @@ -0,0 +1,40 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./lib" + +type I interface { + M() +} + +type PI interface { + PM() +} + +func main() { + var t lib.T + t.M() + t.PM() + + // This is still an error. + // var i1 I = t + // i1.M() + + // This combination is illegal because + // PM requires a pointer receiver. + // var pi1 PI = t + // pi1.PM() + + var pt = &t + pt.M() + pt.PM() + + var i2 I = pt + i2.M() + + var pi2 PI = pt + pi2.PM() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/p.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/p.go new file mode 100644 index 0000000000000000000000000000000000000000..d1e3b991aada1d9775328bde4054610fd2255681 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/p.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Exported interface { + private() +} + +type Implementation struct{} + +func (p *Implementation) private() { println("p.Implementation.private()") } + +var X = new(Implementation) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/prog.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..3ab61f3eb5e87fecc23e7ffc92bd380f67ad5fc4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug324.dir/prog.go @@ -0,0 +1,53 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "./p" +) + +type Exported interface { + private() +} + +type Implementation struct{} + +func (p *Implementation) private() {} + + +func main() { + // nothing unusual here + var x Exported + x = new(Implementation) + x.private() // main.Implementation.private() + + // same here - should be and is legal + var px p.Exported + px = p.X + + // this assignment is correctly illegal: + // px.private undefined (cannot refer to unexported field or method private) + // px.private() + + // this assignment is correctly illegal: + // *Implementation does not implement p.Exported (missing p.private method) + // px = new(Implementation) + + // this assignment is correctly illegal: + // p.Exported does not implement Exported (missing private method) + // x = px + + // this assignment unexpectedly compiles and then executes + defer func() { + recover() + }() + x = px.(Exported) + + println("should not get this far") + + // this is a legitimate call, but because of the previous assignment, + // it invokes the method private in p! + x.private() // p.Implementation.private() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..6ecc5c45ef89224d7f2a20272dc83b200c540e31 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/a.go @@ -0,0 +1,11 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type T interface{} + +func f() T { return nil } + +var Foo T = f() diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..a7735a82e41e57a53d1e026127bc9b787c9a67fb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug335.dir/b.go @@ -0,0 +1,9 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +var Bar = a.Foo diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/io.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/io.go new file mode 100644 index 0000000000000000000000000000000000000000..ca7a5092e9f849cbe04e70c23bf86b90646b4f66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/io.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package io + +type Writer interface { + WrongWrite() +} + +type SectionReader struct { + X int +} + +func SR(*SectionReader) {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..a53d3e8586ed553a73d847d6b8493a95bcb9a513 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug345.dir/main.go @@ -0,0 +1,29 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "bufio" + goio "io" + + "./io" +) + +func main() { + // The errors here complain that io.X != io.X + // for different values of io so they should be + // showing the full import path, which for the + // "./io" import is really ..../go/test/io. + // For example: + // + // main.go:25: cannot use w (type "/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".Writer) as type "io".Writer in function argument: + // io.Writer does not implement io.Writer (missing Write method) + // main.go:27: cannot use &x (type *"io".SectionReader) as type *"/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".SectionReader in function argument + + var w io.Writer + bufio.NewWriter(w) // ERROR "[\w.]+[^.]/io|has incompatible type|cannot use" + var x goio.SectionReader + io.SR(&x) // ERROR "[\w.]+[^.]/io|has incompatible type|cannot use" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/p.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/p.go new file mode 100644 index 0000000000000000000000000000000000000000..2028f740ccdbe959c0501bf45cef7cb27a0e4935 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/p.go @@ -0,0 +1,19 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package p + +type T struct{ x int } +type S struct{} + +func (p *S) get() { +} + +type I interface { + get() +} + +func F(i I) { + i.get() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/prog.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..c278e4dd95ff78799c91ca1032886dfb9ff6d9b0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug367.dir/prog.go @@ -0,0 +1,28 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package main + +import ( + "./p" +) + +type T struct{ *p.S } +type I interface { + get() +} + +func main() { + var t T + p.F(t) + var x interface{} = t + _, ok := x.(I) + if ok { + panic("should not satisfy main.I") + } + _, ok = x.(p.I) + if !ok { + panic("should satisfy p.I") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..03b53a5b90d29c579ad3f20401270e11a141f09d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/main.go @@ -0,0 +1,55 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "flag" + "os" + "runtime" + "testing" + + fast "./fast" + slow "./slow" +) + +var buf = make([]byte, 1048576) + +func BenchmarkFastNonASCII(b *testing.B) { + for i := 0; i < b.N; i++ { + fast.NonASCII(buf, 0) + } +} + +func BenchmarkSlowNonASCII(b *testing.B) { + for i := 0; i < b.N; i++ { + slow.NonASCII(buf, 0) + } +} + +func main() { + testing.Init() + os.Args = []string{os.Args[0], "-test.benchtime=100ms"} + flag.Parse() + + rslow := testing.Benchmark(BenchmarkSlowNonASCII) + rfast := testing.Benchmark(BenchmarkFastNonASCII) + tslow := rslow.NsPerOp() + tfast := rfast.NsPerOp() + + // Optimization should be good for at least 2x, but be forgiving. + // On the ARM simulator we see closer to 1.5x. + speedup := float64(tslow) / float64(tfast) + want := 1.8 + if runtime.GOARCH == "arm" { + want = 1.3 + } + if speedup < want { + // TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on + // a Lenovo x200 (linux-amd64) laptop. + // println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want) + // println("not fast enough") + // os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/pkg.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/pkg.go new file mode 100644 index 0000000000000000000000000000000000000000..9964347250948886b45eb066a59e7bfb20e14c63 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug369.dir/pkg.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkg + +func NonASCII(b []byte, i int) int { + for i = 0; i < len(b); i++ { + if b[i] >= 0x80 { + break + } + } + return i +} + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..e29b813a481d01fedae3e6db0eb4340e1b53e16e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/one.go @@ -0,0 +1,10 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package one + +func Foo() (n int64, _ *int) { + return 42, nil +} + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/two.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/two.go new file mode 100644 index 0000000000000000000000000000000000000000..2a10812d56d0a558febeaf87b3b0ffdf53b7db1a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug377.dir/two.go @@ -0,0 +1,8 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +package two + +import _ "./one" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/pkg.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/pkg.go new file mode 100644 index 0000000000000000000000000000000000000000..92fe4e335a1815d33728a8bb20c58c100e2f53de --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/pkg.go @@ -0,0 +1,7 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkg +type T struct {} +var E T diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/prog.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..b74a82d8241c6f19109d005501e86ab1ea03de1b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug382.dir/prog.go @@ -0,0 +1,13 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file + +// Issue 2529 + +package main + +import "./pkg" + +var x = pkg.E + +var fo = struct{ F pkg.T }{F: x} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..aba8649b5b1d387a32fc96c85048a4c85356bce9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/one.go @@ -0,0 +1,43 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Functions that the inliner exported incorrectly. + +package one + +type T int + +// Issue 2678 +func F1(T *T) bool { return T == nil } + +// Issue 2682. +func F2(c chan int) bool { return c == (<-chan int)(nil) } + +// Use of single named return value. +func F3() (ret []int) { return append(ret, 1) } + +// Call of inlined method with blank receiver. +func (_ *T) M() int { return 1 } +func (t *T) MM() int { return t.M() } + + +// One more like issue 2678 +type S struct { x, y int } +type U []S + +func F4(S int) U { return U{{S,S}} } + +func F5() []*S { + return []*S{ {1,2}, { 3, 4} } +} + +func F6(S int) *U { + return &U{{S,S}} +} + +// Bug in the fix. + +type PB struct { x int } + +func (t *PB) Reset() { *t = PB{} } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg2.go new file mode 100644 index 0000000000000000000000000000000000000000..2ee41f0251072d9d19e5c9696709bf931ee0f39c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg2.go @@ -0,0 +1,25 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Use the functions in one.go so that the inlined +// forms get type-checked. + +package pkg2 + +import "./one" + +func use() { + one.F1(nil) + one.F2(nil) + one.F3() + one.F4(1) + + var t *one.T + t.M() + t.MM() +} + +var V = []one.PB{{}, {}} + +func F() *one.PB diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg3.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg3.go new file mode 100644 index 0000000000000000000000000000000000000000..1403798bd30a4fe473e1a465ff33696f00ca75d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug392.dir/pkg3.go @@ -0,0 +1,13 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Use the functions in pkg2.go so that the inlined +// forms get type-checked. + +package pkg3 + +import "./pkg2" + +var x = pkg2.F() +var v = pkg2.V diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..66eba63f5c1dfd3614f10cc1370409f3dd017533 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/one.go @@ -0,0 +1,10 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package one + +// Issue 2687 +type T struct { int } + +func New(i int) T { return T{i} } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/two.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/two.go new file mode 100644 index 0000000000000000000000000000000000000000..9152bec2545b73f7598d008d048960ff87d5a95d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug396.dir/two.go @@ -0,0 +1,14 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Use the functions in one.go so that the inlined +// forms get type-checked. + +package two + +import "./one" + +func use() { + _ = one.New(1) +} \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..9fc47707891a5467dae3b95515648c0a637302e7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/one.go @@ -0,0 +1,19 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package one + +type T1 int +type T2 []T1 +type T3 T2 + +func F1(T2) { +} + +func (p *T1) M1() T3 { + return nil +} + +func (p T3) M2() { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/two.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/two.go new file mode 100644 index 0000000000000000000000000000000000000000..0c70a23a9e4b5a2aaf3332114ed0b72750bf150d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug404.dir/two.go @@ -0,0 +1,12 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The gccgo compiler would fail on the import statement. +// two.go:10:13: error: use of undefined type ‘one.T2’ + +package two + +import "./one" + +var V one.T3 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..c85b077b66cdefca1c152808fb38edfa9660584c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/one.go @@ -0,0 +1,20 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package one + +// Issue 2877 +type T struct { + f func(t *T, arg int) + g func(t T, arg int) +} + +func (t *T) foo(arg int) {} +func (t T) goo(arg int) {} + +func (t *T) F() { t.f = (*T).foo } +func (t *T) G() { t.g = T.goo } + + + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/two.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/two.go new file mode 100644 index 0000000000000000000000000000000000000000..640305c654167039f53c9245e62401e5e71bd325 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug407.dir/two.go @@ -0,0 +1,15 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Use the functions in one.go so that the inlined +// forms get type-checked. + +package two + +import "./one" + +func use() { + var r one.T + r.F() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..143e600073f010ac118ab6e84f43f614108d259e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/p1.go @@ -0,0 +1,21 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +import "fmt" + +type Fer interface { + f() string +} + +type Object struct{} + +func (this *Object) f() string { + return "Object.f" +} + +func PrintFer(fer Fer) { + fmt.Sprintln(fer.f()) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/prog.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..8945d6543d6d2ed7845ddf7c5cfb78824086a2d8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug414.dir/prog.go @@ -0,0 +1,18 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./p1" + +type MyObject struct { + p1.Fer +} + +func main() { + var b p1.Fer = &p1.Object{} + p1.PrintFer(b) + var c p1.Fer = &MyObject{b} + p1.PrintFer(c) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/p.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/p.go new file mode 100644 index 0000000000000000000000000000000000000000..e86a697643b3f755989a5f4757e13a105fa187eb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/p.go @@ -0,0 +1,14 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type A struct { + s struct{int} +} + +func (a *A) f() { + a.s = struct{int}{0} +} + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/prog.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..1ffde188b7858e0973a3bda3eb602570b4b0bc64 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug415.dir/prog.go @@ -0,0 +1,9 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main +import "./p" +func main() {} +var _ p.A + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/lib.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/lib.go new file mode 100644 index 0000000000000000000000000000000000000000..31df8c600f3a284da534c5d195b3a7a0f3c29d6b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/lib.go @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package lib + +type I interface { + m() string +} + +type T struct{} + +// m is not accessible from outside this package. +func (t *T) m() string { + return "lib.T.m" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..28b41e68a737dfe9e3e43f0b2c99238c673ddc54 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug424.dir/main.go @@ -0,0 +1,97 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Tests that method calls through an interface always +// call the locally defined method localT.m independent +// at which embedding level it is and in which order +// embedding is done. + +package main + +import "./lib" +import "reflect" +import "fmt" + +type localI interface { + m() string +} + +type localT struct{} + +func (t *localT) m() string { + return "main.localT.m" +} + +type myT1 struct { + localT +} + +type myT2 struct { + localT + lib.T +} + +type myT3 struct { + lib.T + localT +} + +func main() { + var i localI + + i = new(localT) + if i.m() != "main.localT.m" { + println("BUG: localT:", i.m(), "called") + } + + i = new(myT1) + if i.m() != "main.localT.m" { + println("BUG: myT1:", i.m(), "called") + } + + i = new(myT2) + if i.m() != "main.localT.m" { + println("BUG: myT2:", i.m(), "called") + } + + t3 := new(myT3) + if t3.m() != "main.localT.m" { + println("BUG: t3:", t3.m(), "called") + } + + i = new(myT3) + if i.m() != "main.localT.m" { + t := reflect.TypeOf(i) + n := t.NumMethod() + for j := 0; j < n; j++ { + m := t.Method(j) + fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type) + } + println("BUG: myT3:", i.m(), "called") + } + + var t4 struct { + localT + lib.T + } + if t4.m() != "main.localT.m" { + println("BUG: t4:", t4.m(), "called") + } + i = &t4 + if i.m() != "main.localT.m" { + println("BUG: myT4:", i.m(), "called") + } + + var t5 struct { + lib.T + localT + } + if t5.m() != "main.localT.m" { + println("BUG: t5:", t5.m(), "called") + } + i = &t5 + if i.m() != "main.localT.m" { + println("BUG: myT5:", i.m(), "called") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/one.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/one.go new file mode 100644 index 0000000000000000000000000000000000000000..633573e51d1cb6ec3437f78cdd14637ca3e63814 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/one.go @@ -0,0 +1,18 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package one + +type I1 interface { + f() +} + +type S1 struct { +} + +func (s S1) f() { +} + +func F1(i1 I1) { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/two.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/two.go new file mode 100644 index 0000000000000000000000000000000000000000..61da121d513270a8b6e7bcb9e10f939a3e315fb6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/two.go @@ -0,0 +1,11 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package two + +import "./one" + +type S2 struct { + one.S1 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/x.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/x.go new file mode 100644 index 0000000000000000000000000000000000000000..585b480c0a918f4cdba9475c0b2e418a25ecac8b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug437.dir/x.go @@ -0,0 +1,25 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test converting a type defined in a different package to an +// interface defined in a third package, where the interface has a +// hidden method. This used to cause a link error with gccgo. + +package main + +import ( + "./one" + "./two" +) + +func F(i1 one.I1) { + switch v := i1.(type) { + case two.S2: + one.F1(v) + } +} + +func main() { + F(nil) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg1.go new file mode 100644 index 0000000000000000000000000000000000000000..291903ca459f3d5dc6ac3db0685938ad1ace0cfb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg1.go @@ -0,0 +1,11 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkg1 + +var x = make(chan interface{}) + +func Do() int { + return (<-x).(int) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg2.go new file mode 100644 index 0000000000000000000000000000000000000000..20d850915dde7ea16e93da6a323939bf7fd98f95 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug448.dir/pkg2.go @@ -0,0 +1,14 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 3843: inlining bug due to wrong receive operator precedence. + +package pkg2 + +import "./pkg1" + +func F() { + pkg1.Do() +} + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..51c6836be7e92914f27c58e97205540956c30fea --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/a.go @@ -0,0 +1,13 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type Foo struct { + int + int8 + error + rune + byte +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..5d388fc413f783de1aa93fe6c0aacab463b87e63 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug460.dir/b.go @@ -0,0 +1,17 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +var x a.Foo + +func main() { + x.int = 20 // ERROR "unexported field|undefined" + x.int8 = 20 // ERROR "unexported field|undefined" + x.error = nil // ERROR "unexported field|undefined" + x.rune = 'a' // ERROR "unexported field|undefined" + x.byte = 20 // ERROR "unexported field|undefined" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..3e5d012e6a1097061c81f04ef6a12f54652c7c4f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/a.go @@ -0,0 +1,76 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type T struct{ A, B int } + +type A []int + +type M map[int]int + +func F1() int { + if (T{1, 2}) == (T{3, 4}) { + return 1 + } + return 0 +} + +func F2() int { + if (M{1: 2}) == nil { + return 1 + } + return 0 +} + +func F3() int { + if nil == (A{}) { + return 1 + } + return 0 +} + +func F4() int { + if a := (A{}); a == nil { + return 1 + } + return 0 +} + +func F5() int { + for k, v := range (M{1: 2}) { + return v - k + } + return 0 +} + +func F6() int { + switch a := (T{1, 1}); a == (T{1, 2}) { + default: + return 1 + } + return 0 +} + +func F7() int { + for m := (M{}); len(m) < (T{1, 2}).A; m[1] = (A{1})[0] { + return 1 + } + return 0 +} + +func F8() int { + if a := (&T{1, 1}); a != nil { + return 1 + } + return 0 +} + +func F9() int { + var a *T + if a = (&T{1, 1}); a != nil { + return 1 + } + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..db7f7315e6ab093f912b540791787a4612d9901f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug465.dir/b.go @@ -0,0 +1,17 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./a" + +func main() { + for _, f := range []func() int{ + a.F1, a.F2, a.F3, a.F4, + a.F5, a.F6, a.F7, a.F8, a.F9} { + if f() > 1 { + panic("f() > 1") + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..e27699c2ef51ff6ad40c00ff43c17a508bbd0b46 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/a.go @@ -0,0 +1,15 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +const N = 2+3i + +func Func() []complex128 { + return []complex128{1, complex(2, 3), complex(4, 5)} +} + +func Mul(z complex128) complex128 { + return z * (3 + 4i) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..04e3626c7524d145c0eefe174db9481b00b46639 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug466.dir/b.go @@ -0,0 +1,30 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./a" + +func main() { + s := a.Func() + if s[0] != 1 { + println(s[0]) + panic("s[0] != 1") + } + if s[1] != 2+3i { + println(s[1]) + panic("s[1] != 2+3i") + } + if s[2] != 4+5i { + println(s[2]) + panic("s[2] != 4+5i") + } + + x := 1 + 2i + y := a.Mul(x) + if y != (1+2i)*(3+4i) { + println(y) + panic("y != (1+2i)*(3+4i)") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..538b554f8e3970b1a043231e172470b27679725e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p1.go @@ -0,0 +1,5 @@ +package p1 + +type SockaddrUnix int + +func (s SockaddrUnix) Error() string { return "blah" } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p2.go new file mode 100644 index 0000000000000000000000000000000000000000..d80d3a30b185d927e9f1f22eaa5d01bb4f604d52 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p2.go @@ -0,0 +1,5 @@ +package p2 + +import "./p1" + +func SockUnix() error { var s *p1.SockaddrUnix; return s } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p3.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p3.go new file mode 100644 index 0000000000000000000000000000000000000000..c795646472fc0a460cb535868f3fa690d80ba8ec --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug467.dir/p3.go @@ -0,0 +1,7 @@ +package main + +import "./p2" + +func main() { + _ = p2.SockUnix() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..cdda735e965704d46b6ea7612539603600bbed77 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p1.go @@ -0,0 +1,7 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +type S struct { X, Y int } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p2.go new file mode 100644 index 0000000000000000000000000000000000000000..dbb46931b825f2d64ca31e62b298946277cc6ae9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug468.dir/p2.go @@ -0,0 +1,25 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "reflect" + + "./p1" +) + +func main() { + var v1 = p1.S{1, 2} + var v2 = struct { X, Y int }{1, 2} + v1 = v2 + t1 := reflect.TypeOf(v1) + t2 := reflect.TypeOf(v2) + if !t1.AssignableTo(t2) { + panic(0) + } + if !t2.AssignableTo(t1) { + panic(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p1.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p1.go new file mode 100644 index 0000000000000000000000000000000000000000..cda1aa7aa8c0f6377f636f4c3c62ceabb3b4857e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p1.go @@ -0,0 +1,17 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.Gosched } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.GC } + +func I() func() string { return runtime.Version } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p2.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p2.go new file mode 100644 index 0000000000000000000000000000000000000000..581ec400200fd1953566be9191c7f5f52b4e2994 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/p2.go @@ -0,0 +1,17 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p2 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.GC } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.Gosched } + +func I() func() string { return runtime.Version } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/z.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/z.go new file mode 100644 index 0000000000000000000000000000000000000000..eb791bf443a3b33babcbf21c090c809ddfc12982 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug472.dir/z.go @@ -0,0 +1,13 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "./p1" + _ "./p2" +) + +func main() { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..b5a2dbcdb88a33e1e444d8aafbbcda8d801022c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/a.go @@ -0,0 +1,9 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p1 + +type S1 struct{} + +func (s S1) f() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..cfd1d273d8e6fc087812cda17a5e822148a6a7f6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug478.dir/b.go @@ -0,0 +1,13 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p2 + +import "./a" + +type S2 struct { + p1.S1 +} + +func (s S2) f() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..eddb4cf0781a17bc105baa5e25082c0a1b546d9e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/a.go @@ -0,0 +1,15 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +type S2 struct {} + +const C = unsafe.Sizeof(S2{}) + +type S1 struct { + S2 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..9f3f5e8f523d1af736ea290690bbfb6a731a12ef --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug479.dir/b.go @@ -0,0 +1,16 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./a" + +type S3 struct { + p.S1 +} + +func main() { + var i interface{} = S3{} + _ = i +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..26a8d1166976a45d3a76128fcc99cd91eefc53d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/a.go @@ -0,0 +1,17 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type S interface{ + F() T +} + +type T struct { + S +} + +type U struct { + error +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..5bd40f6205e32d261a4e53e6b098f788e14583ee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug480.dir/b.go @@ -0,0 +1,13 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +var t a.T + +func F() error { + return a.U{} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..fc494207a1739907bd05d69af9568fba7e3036c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/a.go @@ -0,0 +1,7 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +var p2 = Printf // ERROR "undefined" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..f93328c8da4a04a4efaf6431358dc65a9b358ce5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug488.dir/b.go @@ -0,0 +1,9 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +import . "fmt" + +var p1 = Print diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..90917e55e839ba82754b5543d3c7ac43f5e2e23c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/a.go @@ -0,0 +1,16 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type s struct { + s string +} + +func F1(s s) { +} + +func F2() s { + return s{""} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..5b8c4f2a533eb8d68f24e2c323567a21aca1b33a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug492.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./a" + +func main() { + defer a.F1(a.F2()) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..ac0be937ab2d8cb08e688e364d1ab5cc8672d96f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/a.go @@ -0,0 +1,7 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type MyInt = int diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..e8f8da9af88a42efb6c7a39501edc52a8af61415 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +func F() a.MyInt { + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/c.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/c.go new file mode 100644 index 0000000000000000000000000000000000000000..5a6e889905986aad5ae22b891bf579210d96bb3a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/c.go @@ -0,0 +1,9 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package c + +import "./b" + +var V = b.F() diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..bdbd95c7a3143dabb19a9761bbeca1e0df0acbdf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug504.dir/main.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./c" + +func main() { + println(c.V) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..8e8a2005810fa1fa2a52f98c585d3d60de186b55 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/a.go @@ -0,0 +1,16 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type internal struct { + f1 string + f2 float64 +} + +type S struct { + F struct { + I internal + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/main.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..1b60e40d8d0a448852e5bcbc3542eed2b82f5b4b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug506.dir/main.go @@ -0,0 +1,20 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + + "./a" +) + +var v = a.S{} + +func main() { + want := "{{ 0}}" + if got := fmt.Sprint(v.F); got != want { + panic(got) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..0929adcfb3168da785549f05ec3bd50ff9e195ae --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/a.go @@ -0,0 +1,13 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type I interface { + M() +} + +type S struct { + I I +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..bddce2dd8392d1fc61bb990c4d1f90216b3b87ef --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/b.go @@ -0,0 +1,9 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import . "./a" + +var V2 I diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/c.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/c.go new file mode 100644 index 0000000000000000000000000000000000000000..e67f0fd74e82593e75c3e4421da843adca9e42f1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug507.dir/c.go @@ -0,0 +1,9 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +var V1 = a.S{I: nil} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..db1cfef366d5500182ed07674a31347c0956b34a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/a.go @@ -0,0 +1,13 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +import "reflect" + +type A = map[int] bool + +func F() interface{} { + return reflect.New(reflect.TypeOf((*A)(nil))).Elem().Interface() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..56b0201858cac39d0776c5552c08882aebaba2cb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug510.dir/b.go @@ -0,0 +1,14 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./a" + +func main() { + _, ok := a.F().(*map[int]bool) + if !ok { + panic("bad type") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..33931a07a87bf032fb0899fa05e7d2f363a7a8b2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/a.go @@ -0,0 +1,11 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type S struct{} + +type A = S + +func (A) M() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..f8877d6afd04f6445f1076bdb19b54802c3e440b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/bug511.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +func F() { + a.S{}.M() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..9f51a7a8bc5913c1fe8c0543a4199d095220c11d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/a.go @@ -0,0 +1,12 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type T int + +func (a *T) Foo() [1]string { + var r [1]string + return r +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..41b62d2088070279f643409cde8e4f02b113d3e7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/gcc67968.dir/b.go @@ -0,0 +1,12 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +func F() (interface{}) { + var v *a.T + return v.Foo() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb3b303ea603f4f82b9bf763fb0d0d04d6d9698 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/a.go @@ -0,0 +1,11 @@ +package a + +import "log" + +func Do() { + Do2() +} + +func Do2() { + println(log.Ldate | log.Ltime | log.Lshortfile) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..46d2f55fed63e098ab46e2fe52a1ad612f56e37e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10066.dir/b.go @@ -0,0 +1,7 @@ +package b + +import "./a" + +func test() { + a.Do() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/a.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..c61d02b66a97450f4e678354dd093de6ab50b445 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/a.go @@ -0,0 +1,24 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type m struct { + S string +} + +var g = struct { + m + P string +}{ + m{"a"}, + "", +} + +type S struct{} + +func (s *S) M(p string) { + r := g + r.P = p +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/b.go new file mode 100644 index 0000000000000000000000000000000000000000..09d8911ff4aa77b4a59e0ad9feaf36c11a8843f9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +func F() *a.S { + return &a.S{} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/c.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/c.go new file mode 100644 index 0000000000000000000000000000000000000000..d331495df204d7adf9182c43d1fdd427a6c20844 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10219.dir/c.go @@ -0,0 +1,12 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package c + +import "./b" + +func F() { + s := b.F() + s.M("c") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/other.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/other.go new file mode 100644 index 0000000000000000000000000000000000000000..12908b92053a37249d14a661d92f99f303d6c2a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/other.go @@ -0,0 +1,10 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package other + +type Exported interface { + Do() + secret() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/test.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/test.go new file mode 100644 index 0000000000000000000000000000000000000000..2dfc24af077cce048195d0dcb2570b294a76f27d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue10700.dir/test.go @@ -0,0 +1,49 @@ +// errorcheck -0 -m -l + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "./other" + +type Imported interface { + Do() +} + +type HasAMethod struct { + x int +} + +func (me *HasAMethod) Do() { + println(me.x) +} + +func InMyCode(x *Imported, y *HasAMethod, z *other.Exported) { + x.Do() // ERROR "x\.Do undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface" + x.do() // ERROR "x\.do undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface" + (*x).Do() + x.Dont() // ERROR "x\.Dont undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface" + (*x).Dont() // ERROR "\(\*x\)\.Dont undefined \(type Imported has no field or method Dont\)|reference to undefined field or method" + + y.Do() + y.do() // ERROR "y\.do undefined \(type \*HasAMethod has no field or method do, but does have Do\)|reference to undefined field or method" + (*y).Do() + (*y).do() // ERROR "\(\*y\)\.do undefined \(type HasAMethod has no field or method do, but does have Do\)|reference to undefined field or method" + y.Dont() // ERROR "y\.Dont undefined \(type \*HasAMethod has no field or method Dont\)|reference to undefined field or method" + (*y).Dont() // ERROR "\(\*y\)\.Dont undefined \(type HasAMethod has no field or method Dont\)|reference to undefined field or method" + + z.Do() // ERROR "z\.Do undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface" + z.do() // ERROR "z\.do undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface" + (*z).Do() + (*z).do() // ERROR "\(\*z\)\.do undefined \(type other.Exported has no field or method do, but does have Do\)|reference to undefined field or method" + z.Dont() // ERROR "z\.Dont undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface" + (*z).Dont() // ERROR "\(\*z\)\.Dont undefined \(type other\.Exported has no field or method Dont\)|reference to undefined field or method" + z.secret() // ERROR "z\.secret undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface" + (*z).secret() // ERROR "\(\*z\)\.secret undefined \(cannot refer to unexported field or method secret\)|reference to unexported field or method" + +} + +func main() { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p.go new file mode 100644 index 0000000000000000000000000000000000000000..81b412aef13a9f459f288dcea92b2f165a2b6ddd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p.go @@ -0,0 +1,9 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func Int32(i int32) *int32 { + return &i +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p_test.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p_test.go new file mode 100644 index 0000000000000000000000000000000000000000..412352d7c5e1f36026ef84600a8a8763653d3cbb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11053.dir/p_test.go @@ -0,0 +1,51 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "./p" + "fmt" +) + +type I interface { + Add(out *P) +} + +type P struct { + V *int32 +} + +type T struct{} + +var x int32 = 42 + +func Int32x(i int32) *int32 { + return &i +} + +func (T) Add(out *P) { + out.V = p.Int32(x) // inlined, p.i.2 moved to heap +} + +var PP P +var out *P = &PP + +func F(s I) interface{} { + s.Add(out) // not inlined. + return out +} + +var s T + +func main() { + println("Starting") + fmt.Sprint(new(int32)) + resp := F(s).(*P) + println("Before, *resp.V=", *resp.V) // Trashes *resp.V in process of printing. + println("After, *resp.V=", *resp.V) + if got, want := *resp.V, int32(42); got != want { + fmt.Printf("FAIL, got %v, want %v", got, want) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm.go new file mode 100644 index 0000000000000000000000000000000000000000..c64302bd505e4562cc4529d9f3ca13b927a8e6e4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm.go @@ -0,0 +1,9 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ppc64 || ppc64le + +package main + +func syncIcache(p uintptr) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_generic.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_generic.go new file mode 100644 index 0000000000000000000000000000000000000000..a8b8f6a5e4f2af436f2bbd65b4b64b94f7bfa9bc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_generic.go @@ -0,0 +1,10 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !ppc64 && !ppc64le + +package main + +func syncIcache(p uintptr) { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64.s b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64.s new file mode 100644 index 0000000000000000000000000000000000000000..125a197ed8e1f74f18e181546555895e85b5a8c0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64.s @@ -0,0 +1,13 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +// func syncIcache(p uintptr) +TEXT main·syncIcache(SB), NOSPLIT|NOFRAME, $0-0 + SYNC + MOVD (R3), R3 + ICBI (R3) + ISYNC + RET diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64le.s b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64le.s new file mode 100644 index 0000000000000000000000000000000000000000..125a197ed8e1f74f18e181546555895e85b5a8c0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue11656.dir/asm_ppc64le.s @@ -0,0 +1,13 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +// func syncIcache(p uintptr) +TEXT main·syncIcache(SB), NOSPLIT|NOFRAME, $0-0 + SYNC + MOVD (R3), R3 + ICBI (R3) + ISYNC + RET diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45606.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45606.go new file mode 100644 index 0000000000000000000000000000000000000000..1b52b4e7d5ac0a853b22518779cb3876ec805dd5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45606.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func x() { + func() func() { + return func() { + f := func() {} + g, _ := f, 0 + g() + } + }()() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4562.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4562.go new file mode 100644 index 0000000000000000000000000000000000000000..8c958f5725d66a97faf5605945a4428fc5681958 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4562.go @@ -0,0 +1,49 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "runtime" + "strings" +) + +type T struct { + val int +} + +func main() { + defer expectError(22) + var pT *T + switch pT.val { // error should be here - line 22 + case 0: + fmt.Println("0") + case 1: // used to show up here instead + fmt.Println("1") + case 2: + fmt.Println("2") + } + fmt.Println("finished") +} + +func expectError(expectLine int) { + if recover() == nil { + panic("did not crash") + } + for i := 1;; i++ { + _, file, line, ok := runtime.Caller(i) + if !ok { + panic("cannot find issue4562.go on stack") + } + if strings.HasSuffix(file, "issue4562.go") { + if line != expectLine { + panic(fmt.Sprintf("crashed at line %d, wanted line %d", line, expectLine)) + } + break + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45665.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45665.go new file mode 100644 index 0000000000000000000000000000000000000000..2981a4904c1d44f21f9a203f2feb1d1ab0a9ff29 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45665.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + Get([]string{"a", "b"}) +} + +func Get(ss []string) *[2]string { + return (*[2]string)(ss) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45693.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45693.go new file mode 100644 index 0000000000000000000000000000000000000000..20a0cec8ffa76fce348c6acb5bcf0f7dc9a013c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45693.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 45693: ICE with register args. + +package p + +func f() { + var s string + s = s + "" + s + "" + s + "" + for { + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45706.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45706.go new file mode 100644 index 0000000000000000000000000000000000000000..6518dbf090f62c48c38fb2deb41b406d94c41253 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45706.go @@ -0,0 +1,25 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var i int +var arr []*int +var f func() int + +func g() { + for i, *(arr[f()]) = range []int{} { + } +} + +func h() { + var x int + var f func() int + var arr []int + var arr2 [][0]rune + for arr[x], arr2[arr[f()]][x] = range "" { + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45743.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45743.go new file mode 100644 index 0000000000000000000000000000000000000000..0b30e0f2a4dc8ba9fac380ccc49855af67ad14a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45743.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func fn() func(interface{}) { + return func(o interface{}) { + switch v := o.(type) { + case *int: + *v = 1 + } + } +} + +func main() { + fn() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45804.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45804.go new file mode 100644 index 0000000000000000000000000000000000000000..28d42c8d8150dbdf69a4e28e0cfa061e4a4f495c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45804.go @@ -0,0 +1,19 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func g() int +func h(int) + +var b bool + +func f() { + did := g() + if !did && b { // ERROR "invalid operation" + h(x) // ERROR "undefined" + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4585.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4585.go new file mode 100644 index 0000000000000000000000000000000000000000..9191ec5df88dcd5c3d3b1bdcd869b489301a744d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4585.go @@ -0,0 +1,151 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4585: comparisons and hashes process blank +// fields and padding in structs. + +package main + +import "unsafe" + +// T is a structure with padding. +type T struct { + A int16 + B int64 + C int16 + D int64 + Dummy [64]byte +} + +// U is a structure with a blank field +type U struct { + A, _, B int + Dummy [64]byte +} + +// USmall is like U but the frontend will inline comparison +// instead of calling the generated eq function. +type USmall struct { + A, _, B int32 +} + +// V has padding but not on the first field. +type V struct { + A1, A2, A3 int32 + B int16 + C int32 +} + +// W has padding at the end. +type W struct { + A1, A2, A3 int32 + B int32 + C int8 +} + +func test1() { + var a, b U + m := make(map[U]int) + copy((*[16]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B = 1, 2 + b.A, b.B = 1, 2 + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test2() { + var a, b T + m := make(map[T]int) + + copy((*[16]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B, a.C, a.D = 1, 2, 3, 4 + b.A, b.B, b.C, b.D = 1, 2, 3, 4 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test3() { + var a, b USmall + copy((*[12]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B = 1, 2 + b.A, b.B = 1, 2 + if a != b { + panic("broken equality: a != b") + } +} + +func test4() { + var a, b V + m := make(map[V]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test5() { + var a, b W + m := make(map[W]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func main() { + test1() + test2() + test3() + test4() + test5() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45851.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45851.go new file mode 100644 index 0000000000000000000000000000000000000000..b137071e4fdb85b12c8d12656b6522b123216545 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45851.go @@ -0,0 +1,68 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This tickles a stack-allocation bug when the register ABI is enabled. +// The original report was from cue, internal/core/adt/equality.go, +// function equalVertex. + +// In the failing case, something bad gets passed to equalTerminal. + +package main + +import "fmt" + +type Kind uint16 +type Flag uint16 + +const ( + allKinds Kind = 1 + TopKind Kind = (allKinds - 1) +) +type Value interface { + Kind() Kind +} +type Vertex struct { + BaseValue Value + name string +} +func (v *Vertex) Kind() Kind { + return TopKind +} + +func main() { + vA := &Vertex{name:"vA",} + vB := &Vertex{name:"vB",} + vX := &Vertex{name:"vX",} + vA.BaseValue = vX + vB.BaseValue = vX + _ = equalVertex(vA, vB, Flag(1)) +} + +var foo string + +//go:noinline +func (v *Vertex) IsClosedStruct() bool { + return true +} + +func equalVertex(x *Vertex, v Value, flags Flag) bool { + y, ok := v.(*Vertex) + if !ok { + return false + } + v, ok1 := x.BaseValue.(Value) + w, ok2 := y.BaseValue.(Value) + if !ok1 && !ok2 { + return true // both are struct or list. + } + return equalTerminal(v, w, flags) +} + +//go:noinline +func equalTerminal(x Value, y Value, flags Flag) bool { + foo = fmt.Sprintf("EQclosed %s %s %d\n", x.(*Vertex).name, y.(*Vertex).name, flags) + return true +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4590.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4590.go new file mode 100644 index 0000000000000000000000000000000000000000..faeb1adef23af1522c9d57239a52ae737922d852 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4590.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4590: linker fails on multiple imports of +// an anonymous struct with methods. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45913.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45913.go new file mode 100644 index 0000000000000000000000000000000000000000..aa86028c51a73416020a29d645700eb61af16055 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45913.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +func f(s1, s2 string) { fmt.Printf("%s %s", s1, s2) } + +func main() { + f([2]string{"a", "b"}...) // ERROR "invalid use of .*[.][.][.]|cannot use [.][.][.] in call to non-variadic" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45947.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45947.go new file mode 100644 index 0000000000000000000000000000000000000000..408644934036923d54c65c1855f7997a980deca2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45947.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + _ = func() func() { + return func() { + l: + goto l + } + }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue45948.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue45948.go new file mode 100644 index 0000000000000000000000000000000000000000..37f8e70e2bb23b8bdff148df5c3864d4cb1d44e8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue45948.go @@ -0,0 +1,16 @@ +// compile -N + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 45948: assert in debug generation for degenerate +// function with infinite loop. + +package p + +func f(p int) { +L: + goto L + +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4610.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4610.go new file mode 100644 index 0000000000000000000000000000000000000000..d56c6d3e8cd899ffd8ad167f2b50815c7ef09545 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4610.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type bar struct { + x int +} + +func main() { + var foo bar + _ = &foo{} // ERROR "is not a type|expected .;." +} // GCCGO_ERROR "expected declaration" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4614.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4614.go new file mode 100644 index 0000000000000000000000000000000000000000..ad378d8c531406fd05934ab570fdc6dd33060f4b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4614.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4614: slicing of nil slices confuses the compiler +// with a uintptr(nil) node. + +package p + +import "unsafe" + +var n int + +var _ = []int(nil)[1:] +var _ = []int(nil)[n:] + +var _ = uintptr(unsafe.Pointer(nil)) +var _ = unsafe.Pointer(uintptr(0)) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4618.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4618.go new file mode 100644 index 0000000000000000000000000000000000000000..0ba95230cf33523f176b827228ed1fcdfdbc8010 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4618.go @@ -0,0 +1,41 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "runtime" + "testing" +) + +type T struct { int } + +var globl *T + +func F() { + t := &T{} + globl = t +} + +func G() { + t := &T{} + _ = t +} + +func main() { + nf := testing.AllocsPerRun(100, F) + ng := testing.AllocsPerRun(100, G) + if int(nf) > 1 { + fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) + os.Exit(1) + } + if int(ng) != 0 && (runtime.Compiler != "gccgo" || int(ng) != 1) { + fmt.Printf("AllocsPerRun(100, G) = %v, want 0\n", ng) + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4620.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4620.go new file mode 100644 index 0000000000000000000000000000000000000000..5aa29086f79a3ec34bdf490e15e3cd5465482fe6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4620.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4620: map indexes are not evaluated before assignment of other elements + +package main + +import "fmt" + +func main() { + m := map[int]int{0:1} + i := 0 + i, m[i] = 1, 2 + if m[0] != 2 { + fmt.Println(m) + panic("m[i] != 2") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46234.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46234.go new file mode 100644 index 0000000000000000000000000000000000000000..9c346dd95c3a919a0ea6cdb60e04d947fc5d5587 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46234.go @@ -0,0 +1,103 @@ +// buildrun -t 45 + +//go:build !js && !wasip1 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Ensure that runtime traceback does not infinite loop for +// the testcase below. + +package main + +import ( + "bytes" + "io/ioutil" + "log" + "os" + "os/exec" + "path/filepath" +) + +const prog = ` + +package main + +import "context" + +var gpi *int + +type nAO struct { + eE bool +} + +type NAO func(*nAO) + +func WEA() NAO { + return func(o *nAO) { o.eE = true } +} + +type R struct { + cM *CM +} + +type CM int + +type A string + +func (m *CM) NewA(ctx context.Context, cN string, nn *nAO, opts ...NAO) (*A, error) { + for _, o := range opts { + o(nn) + } + s := A("foo") + return &s, nil +} + +func (r *R) CA(ctx context.Context, cN string, nn *nAO) (*int, error) { + cA, err := r.cM.NewA(ctx, cN, nn, WEA(), WEA()) + if err == nil { + return nil, err + } + println(cA) + x := int(42) + return &x, nil +} + +func main() { + c := CM(1) + r := R{cM: &c} + var ctx context.Context + nnr := nAO{} + pi, err := r.CA(ctx, "foo", nil) + if err != nil { + panic("bad") + } + println(nnr.eE) + gpi = pi +} +` + +func main() { + dir, err := ioutil.TempDir("", "46234") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(dir) + + file := filepath.Join(dir, "main.go") + if err := ioutil.WriteFile(file, []byte(prog), 0655); err != nil { + log.Fatalf("Write error %v", err) + } + + cmd := exec.Command("go", "run", file) + output, err := cmd.CombinedOutput() + if err == nil { + log.Fatalf("Passed, expected an error") + } + + want := []byte("nil pointer dereference") + if !bytes.Contains(output, want) { + log.Fatalf("Unmatched error message %q:\nin\n%s\nError: %v", want, output, err) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46304.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46304.go new file mode 100644 index 0000000000000000000000000000000000000000..b8ecfc93a5976c026c655843b92fb18926df2ad3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46304.go @@ -0,0 +1,76 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This testcase caused a crash when the register ABI was in effect, +// on amd64 (problem with register allocation). + +package main + +type Op struct { + tag string + _x []string + _q [20]uint64 + plist []P +} + +type P struct { + tag string + _x [10]uint64 + b bool +} + +type M int + +//go:noinline +func (w *M) walkP(p *P) *P { + np := &P{} + *np = *p + np.tag += "new" + return np +} + +func (w *M) walkOp(op *Op) *Op { + if op == nil { + return nil + } + + orig := op + cloned := false + clone := func() { + if !cloned { + cloned = true + op = &Op{} + *op = *orig + } + } + + pCloned := false + for i := range op.plist { + if s := w.walkP(&op.plist[i]); s != &op.plist[i] { + if !pCloned { + pCloned = true + clone() + op.plist = make([]P, len(orig.plist)) + copy(op.plist, orig.plist) + } + op.plist[i] = *s + } + } + + return op +} + +func main() { + var ww M + w := &ww + p1 := P{tag: "a"} + p1._x[1] = 9 + o := Op{tag: "old", plist: []P{p1}} + no := w.walkOp(&o) + if no.plist[0].tag != "anew" { + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46386.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46386.go new file mode 100644 index 0000000000000000000000000000000000000000..89dea8abf3ba130703934cf3b426207e932fc4d8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46386.go @@ -0,0 +1,32 @@ +// compile -p=main + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + M() interface{} +} + +type S1 struct{} + +func (S1) M() interface{} { + return nil +} + +type EI interface{} + +type S struct{} + +func (S) M(as interface{ I }) {} + +func f() interface{ EI } { + return &S1{} +} + +func main() { + var i interface{ I } + (&S{}).M(i) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46525.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46525.go new file mode 100644 index 0000000000000000000000000000000000000000..164e1473ce610fef79c197dda49015705a4c8956 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46525.go @@ -0,0 +1,14 @@ +// errorcheck -lang=go1.16 + +// Copyright 2021 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package p + +import "unsafe" + +func main() { + _ = unsafe.Add(unsafe.Pointer(nil), 0) // ERROR "unsafe.Add requires go1.17 or later" + _ = unsafe.Slice(new(byte), 1) // ERROR "unsafe.Slice requires go1.17 or later" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4654.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4654.go new file mode 100644 index 0000000000000000000000000000000000000000..76aff76a6780332f61822e4ecb4d25a4220a3753 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4654.go @@ -0,0 +1,71 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4654. +// Check error for conversion and 'not used' in defer/go. + +package p + +import "unsafe" + +func f() { + defer int(0) // ERROR "defer requires function call, not conversion|is not used" + go string([]byte("abc")) // ERROR "go requires function call, not conversion|is not used" + + var c complex128 + var f float64 + var t struct {X int} + + var x []int + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer cap(x) // ERROR "defer discards result of cap|is not used" + defer complex(1, 2) // ERROR "defer discards result of complex|is not used" + defer complex(f, 1) // ERROR "defer discards result of complex|is not used" + defer imag(1i) // ERROR "defer discards result of imag|is not used" + defer imag(c) // ERROR "defer discards result of imag|is not used" + defer len(x) // ERROR "defer discards result of len|is not used" + defer make([]int, 1) // ERROR "defer discards result of make|is not used" + defer make(chan bool) // ERROR "defer discards result of make|is not used" + defer make(map[string]int) // ERROR "defer discards result of make|is not used" + defer new(int) // ERROR "defer discards result of new|is not used" + defer real(1i) // ERROR "defer discards result of real|is not used" + defer real(c) // ERROR "defer discards result of real|is not used" + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof|is not used" + defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof|is not used" + defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof|is not used" + + defer copy(x, x) // ok + m := make(map[int]int) + defer delete(m, 1) // ok + defer panic(1) // ok + defer print(1) // ok + defer println(1) // ok + defer recover() // ok + + int(0) // ERROR "int\(0\) evaluated but not used|is not used" + string([]byte("abc")) // ERROR "string\(.*\) evaluated but not used|is not used" + + append(x, 1) // ERROR "not used" + cap(x) // ERROR "not used" + complex(1, 2) // ERROR "not used" + complex(f, 1) // ERROR "not used" + imag(1i) // ERROR "not used" + imag(c) // ERROR "not used" + len(x) // ERROR "not used" + make([]int, 1) // ERROR "not used" + make(chan bool) // ERROR "not used" + make(map[string]int) // ERROR "not used" + new(int) // ERROR "not used" + real(1i) // ERROR "not used" + real(c) // ERROR "not used" + append(x, 1) // ERROR "not used" + append(x, 1) // ERROR "not used" + unsafe.Alignof(t.X) // ERROR "not used" + unsafe.Offsetof(t.X) // ERROR "not used" + unsafe.Sizeof(t) // ERROR "not used" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46556.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46556.go new file mode 100644 index 0000000000000000000000000000000000000000..b159f61b0c5034309d27288ab9a425834bb6ea1d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46556.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type A = interface{} +type B interface{} + +// Test that embedding both anonymous and defined types is supported. +type C interface { + A + B +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4663.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4663.go new file mode 100644 index 0000000000000000000000000000000000000000..971290d8ddf8704c3b78bd1430bc87e77abf29ab --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4663.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4663. +// Make sure 'not used' message is placed correctly. + +package main + +func a(b int) int64 { + b // ERROR "not used" + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46653.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46653.go new file mode 100644 index 0000000000000000000000000000000000000000..e6283b1de50c1ef55ebd90796a0b4a791d7bc7e8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46653.go @@ -0,0 +1,10 @@ +// runindir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test to verify compiler and linker handling of multiple +// competing map.zero symbol definitions. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4667.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4667.go new file mode 100644 index 0000000000000000000000000000000000000000..31b32841be3063049d4fb451527cbc79115a704f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4667.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "testing" +) + +var globl *int + +func G() { + F() +} + +func F() { + var x int + globl = &x +} + +func main() { + nf := testing.AllocsPerRun(100, F) + ng := testing.AllocsPerRun(100, G) + if int(nf) > 1 { + fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) + os.Exit(1) + } + if int(ng) > 1 { + fmt.Printf("AllocsPerRun(100, G) = %v, want 1\n", ng) + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46720.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46720.go new file mode 100644 index 0000000000000000000000000000000000000000..3b0151ae84f49888b3abd5701fca59d62cfcfb20 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46720.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + nonce := make([]byte, 24) + g((*[24]byte)(nonce)) +} + +//go:noinline +func g(*[24]byte) {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46725.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46725.go new file mode 100644 index 0000000000000000000000000000000000000000..f6e443e60f062f66753e0935943a636c685c3a5d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46725.go @@ -0,0 +1,48 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "runtime" + +type T [4]int // N.B., [4]int avoids runtime's tiny object allocator + +//go:noinline +func g(x []*T) ([]*T, []*T) { return x, x } + +func main() { + const Jenny = 8675309 + s := [10]*T{{Jenny}} + + done := make(chan struct{}) + runtime.SetFinalizer(s[0], func(p *T) { close(done) }) + + var h, _ interface{} = g(s[:]) + + if wait(done) { + panic("GC'd early") + } + + if h.([]*T)[0][0] != Jenny { + panic("lost Jenny's number") + } + + if !wait(done) { + panic("never GC'd") + } +} + +func wait(done <-chan struct{}) bool { + for i := 0; i < 10; i++ { + runtime.GC() + select { + case <-done: + return true + default: + } + } + return false +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46749.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46749.go new file mode 100644 index 0000000000000000000000000000000000000000..faf1f884a6b40cde9d83a606b77a25314091315f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46749.go @@ -0,0 +1,37 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var s string +var b bool +var i int +var iface interface{} + +var ( + _ = "" + b // ERROR "invalid operation.*mismatched types.*untyped string and bool" + _ = "" + i // ERROR "invalid operation.*mismatched types.*untyped string and int" + _ = "" + nil // ERROR "invalid operation.*mismatched types.*untyped string and nil|(untyped nil)" +) + +var ( + _ = s + false // ERROR "invalid operation.*mismatched types.*string and untyped bool" + _ = s + 1 // ERROR "invalid operation.*mismatched types.*string and untyped int" + _ = s + nil // ERROR "invalid operation.*mismatched types.*string and nil|(untyped nil)" +) + +var ( + _ = "" + false // ERROR "invalid operation.*mismatched types.*untyped string and untyped bool" + _ = "" + 1 // ERROR "invalid operation.*mismatched types.*untyped string and untyped int" +) + +var ( + _ = b + 1 // ERROR "invalid operation.*mismatched types.*bool and untyped int" + _ = i + false // ERROR "invalid operation.*mismatched types.*int and untyped bool" + _ = iface + 1 // ERROR "invalid operation.*mismatched types.*interface *{} and int" + _ = iface + 1.0 // ERROR "invalid operation.*mismatched types.*interface *{} and float64" + _ = iface + false // ERROR "invalid operation.*mismatched types.*interface *{} and bool" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46903.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46903.go new file mode 100644 index 0000000000000000000000000000000000000000..3a0b6049fd55882b213a6962aed85cdb575a197b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46903.go @@ -0,0 +1,32 @@ +// run +//go:build cgo + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "runtime/cgo" + +type A struct { + B + _ cgo.Incomplete +} +type B struct{ x byte } +type I interface{ M() *B } + +func (p *B) M() *B { return p } + +var ( + a A + i I = &a +) + +func main() { + got, want := i.M(), &a.B + if got != want { + println(got, "!=", want) + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46907.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46907.go new file mode 100644 index 0000000000000000000000000000000000000000..bd82f4f2b100a9674a0dddb464befaa08dfe7d69 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46907.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(b []byte) []byte { + return (*[32]byte)(b[:32])[:] +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46938.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46938.go new file mode 100644 index 0000000000000000000000000000000000000000..87532d47694edc4a275d923d00c847227de929b4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46938.go @@ -0,0 +1,29 @@ +// run -gcflags="-d=checkptr" + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "strings" + "unsafe" +) + +func main() { + defer func() { + err := recover() + if err == nil { + panic("expected panic") + } + if got := err.(error).Error(); !strings.Contains(got, "slice bounds out of range") { + panic("expected panic slice out of bound, got " + got) + } + }() + s := make([]int64, 100) + p := unsafe.Pointer(&s[0]) + n := 1000 + + _ = (*[10]int64)(p)[:n:n] +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue46957.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue46957.go new file mode 100644 index 0000000000000000000000000000000000000000..6c1c0fe0c28981f3dbb19d7859181c55d3cdc9bc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue46957.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f(a int, b ...int) {} + +func main() { + f(nil...) // ERROR "not enough arguments in call to f\n\thave \(nil\)\n\twant \(int, \[\]int\)|not enough arguments" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47068.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47068.go new file mode 100644 index 0000000000000000000000000000000000000000..af6f1341729458e04aba9a8a7110ec999540bc2a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47068.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47087.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47087.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47087.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47131.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47131.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47131.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47185.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47185.go new file mode 100644 index 0000000000000000000000000000000000000000..91c7e0ad3a5d990922d964b103b638f02c93ec66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47185.go @@ -0,0 +1,12 @@ +// runindir + +//go:build cgo + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Another test to verify compiler and linker handling of multiple +// competing map.zero symbol definitions. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47201.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47201.go new file mode 100644 index 0000000000000000000000000000000000000000..e3a470b4195ab9ee0b49030efa76975b00b284f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47201.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47227.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47227.go new file mode 100644 index 0000000000000000000000000000000000000000..14c3b1521277bd791c0ab87153a21fe10abc9b83 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47227.go @@ -0,0 +1,22 @@ +// run fake-arg-to-force-use-of-go-run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build cgo + +package main + +// void f(int *p) { *p = 0x12345678; } +import "C" + +func main() { + var x C.int + func() { + defer C.f(&x) + }() + if x != 0x12345678 { + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47317.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47317.go new file mode 100644 index 0000000000000000000000000000000000000000..3548e90d020d4b8d991f71b6169610de9144946f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47317.go @@ -0,0 +1,7 @@ +// builddir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4734.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4734.go new file mode 100644 index 0000000000000000000000000000000000000000..45e609d5084cdb69aeda777234dea18c5cfb1889 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4734.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Caused gccgo to emit multiple definitions of the same symbol. + +package p + +type S1 struct{} + +func (s *S1) M() {} + +type S2 struct { + F struct{ *S1 } +} + +func F() { + _ = struct{ *S1 }{} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4748.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4748.go new file mode 100644 index 0000000000000000000000000000000000000000..f7c77cf882f3f5c0e947f1e0f3e182d10d51ce67 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4748.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4748. +// This program used to complain because inlining created two exit labels. + +package main + +func jump() { + goto exit +exit: + return +} +func main() { + jump() + jump() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4752.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4752.go new file mode 100644 index 0000000000000000000000000000000000000000..af7bb92b58a7989b7a10733d42e5b77cfd6fe14f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4752.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func F(xi, yi interface{}) uint64 { + x, y := xi.(uint64), yi.(uint64) + return x &^ y +} + +func G(xi, yi interface{}) uint64 { + return xi.(uint64) &^ yi.(uint64) // generates incorrect code +} + +func main() { + var x, y uint64 = 0, 1 << 63 + f := F(x, y) + g := G(x, y) + if f != 0 || g != 0 { + println("F", f, "G", g) + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47712.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47712.go new file mode 100644 index 0000000000000000000000000000000000000000..81a2681592e92cc1dfee1ef94018624b9040e5e0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47712.go @@ -0,0 +1,23 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + if false { + defer func() { + _ = recover() + }() + } +} + +func g() { + for false { + defer func() { + _ = recover() + }() + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4776.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4776.go new file mode 100644 index 0000000000000000000000000000000000000000..a1009ad96130919bba718f9a0f8796527f53a76a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4776.go @@ -0,0 +1,10 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4776: missing package declaration error should be fatal. + +type MyInt int32 // ERROR "package statement must be first|package clause" + diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47771.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47771.go new file mode 100644 index 0000000000000000000000000000000000000000..a434bffe4b1ad101bef7b6695872614371f35863 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47771.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// gofrontend miscompiled some cases of append(s, make(typ, ln)...). + +package main + +var g int + +func main() { + a := []*int{&g, &g, &g, &g} + a = append(a[:0], make([]*int, len(a) - 1)...) + if len(a) != 3 || a[0] != nil || a[1] != nil || a[2] != nil { + panic(a) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4785.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4785.go new file mode 100644 index 0000000000000000000000000000000000000000..d0bcd56c71117354b1ff0f531eb233ebf59fa393 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4785.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 4785: used to fail to compile + +package main + +func t(x, y interface{}) interface{} { + return x.(float64) > y.(float64) +} + +func main() { + v := t(1.0, 2.0) + if v != false { + panic("bad comparison") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue47928.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue47928.go new file mode 100644 index 0000000000000000000000000000000000000000..3bc291dd3f1b4ea8746b7e52155467b18eb5a562 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue47928.go @@ -0,0 +1,21 @@ +// run -goexperiment fieldtrack + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var i interface{} = new(T) + if _, ok := i.(interface{ Bad() }); ok { + panic("FAIL") + } +} + +type T struct{ U } + +type U struct{} + +//go:nointerface +func (*U) Bad() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue48026.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue48026.go new file mode 100644 index 0000000000000000000000000000000000000000..a693d33b45f00f422971f371c9b79f53c2a1675f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue48026.go @@ -0,0 +1,26 @@ +// compile -d=ssa/check/on + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var i int + +type t struct { + a, b, c, d, e int +} + +func f(p t, q int) int { + var a, b, c, d, e, f, g int + var h, i, j, k, l, m int + _, _, _, _, _, _, _ = a, b, c, d, e, f, g + _, _, _, _, _, _ = h, i, j, k, l, m + return 0 +} + +func g() int { + var v t + return f(v, 1< 1 { + nprev = ns[len(ns)-2] + } + isIndirect := false + for n := nlast / 2; n > nprev; n /= 2 { + if n%2 == 1 { + isIndirect = true + break + } + } + fmt.Print(")") + if isIndirect { + fmt.Print(` // ERROR "indirection|embedded via a pointer"`) + } + fmt.Print("\n") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.go new file mode 100644 index 0000000000000000000000000000000000000000..3a2e9727514244283760bbe6a376fcc789feafb3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f(j int) { +loop: + for i := 0; i < 4; i++ { + if i == 1 { + continue loop + } + println(j, i) + } +} + +func main() { +loop: + for j := 0; j < 5; j++ { + f(j) + if j == 3 { + break loop + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.out new file mode 100644 index 0000000000000000000000000000000000000000..326d41365a9ce2ee460a8e52939100f06e495a16 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100.out @@ -0,0 +1,12 @@ +0 0 +0 2 +0 3 +1 0 +1 2 +1 3 +2 0 +2 2 +2 3 +3 0 +3 2 +3 3 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.go new file mode 100644 index 0000000000000000000000000000000000000000..992ff96d547151efe6b3b7a00810b0ac67f3d218 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func r(j int) { +loop: + for i, c := range "goclang" { + if i == 2 { + continue loop + } + println(string(c)) + } +} + +func main() { +loop: + for j := 0; j < 4; j++ { + r(j) + if j == 0 { + break loop + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.out new file mode 100644 index 0000000000000000000000000000000000000000..d5abb928ee500f83b07a48a82ae7cdcc5f2d6ee5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49100b.out @@ -0,0 +1,6 @@ +g +o +l +a +n +g diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49110.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49110.go new file mode 100644 index 0000000000000000000000000000000000000000..5e1bde9f0060b7ed1ed177e53c7afe77a4a24b1e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49110.go @@ -0,0 +1,16 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "reflect" + +func main() { + _ = reflect.StructOf([]reflect.StructField{ + {Name: "_", PkgPath: "main", Type: reflect.TypeOf(int(0))}, + {Name: "_", PkgPath: "main", Type: reflect.TypeOf(int(0))}, + }) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49122.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49122.go new file mode 100644 index 0000000000000000000000000000000000000000..c62a627dae079f4f6673538b8652a86e28c9c9e8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49122.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var B []bool +var N int + +func f(p bool, m map[bool]bool) bool { + var q bool + _ = p || N&N < N || B[0] || B[0] + return p && q && m[q] +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49143.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49143.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49143.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.go new file mode 100644 index 0000000000000000000000000000000000000000..d66668196e996e33a272188d94aff67fb2907d4f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f(j int) { +loop: + switch j { + case 1: + break loop + default: + println(j) + } +} + +func main() { +loop: + for j := 0; j < 5; j++ { + f(j) + if j == 3 { + break loop + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.out new file mode 100644 index 0000000000000000000000000000000000000000..1556c06ea8333942b224f233562f1ab167635aff --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49145.out @@ -0,0 +1,3 @@ +0 +2 +3 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49240.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49240.go new file mode 100644 index 0000000000000000000000000000000000000000..26929fe1a2a0a2b454e63ffec8b68f6e32040e8e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49240.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + go copy([]int{1: 0}, []int{}) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49249.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49249.go new file mode 100644 index 0000000000000000000000000000000000000000..f152a5a7012f4d66b67e022c57a6d4c174f2518e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49249.go @@ -0,0 +1,55 @@ +// compile -l + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() int { + var a, b struct { + s struct { + s struct { + byte + float32 + } + } + } + _ = a + + return func() int { + return func() int { + a = struct { + s struct { + s struct { + byte + float32 + } + } + }{b.s} + return 0 + }() + }() +} + +func g() int { + var a, b struct { + s [1][1]struct { + byte + float32 + } + } + _ = a + + return func() int { + return func() int { + a = struct { + s [1][1]struct { + byte + float32 + } + }{b.s} + return 0 + }() + }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49282.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49282.go new file mode 100644 index 0000000000000000000000000000000000000000..7543075ca18d3c7afd2f2466c6a7a872eee864bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49282.go @@ -0,0 +1,44 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +//go:noinline +func g(d uintptr, a, m []int, s struct { + a, b, c, d, e int +}, u uint) { + _ = a + _ = m + _ = s + func() { + for i := 0; i < 5; i++ { + _ = a + _ = m + _, _ = s, s + } + }() +} + +var One float64 = 1.0 + +func f(d uintptr) { + var a, m []int + var s struct { + a, b, c, d, e int + } + + g(d, a, m, s, uint(One)) // Uint of not-a-constant inserts a conditional, necessary to bug + + defer func() uint { + return 0 + }() +} + +var d uintptr + +func h() { + f(d) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4932.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4932.go new file mode 100644 index 0000000000000000000000000000000000000000..2a6bc699f0f495a4ba753f86ea7d118e35cc40d6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4932.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4932: regression in export of composite literals. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49368.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49368.go new file mode 100644 index 0000000000000000000000000000000000000000..2339048e3d12b76325cf6af1c05bbc89f992401f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49368.go @@ -0,0 +1,11 @@ +// errorcheck -lang=go1.17 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type _ interface { + int // ERROR "embedding non-interface type int requires go1\.18 or later \(-lang was set to go1\.17; check go.mod\)" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49378.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49378.go new file mode 100644 index 0000000000000000000000000000000000000000..70f466c929faab16b76ef99a9d2ce90e4bf3563a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49378.go @@ -0,0 +1,25 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(i int) { + var s1 struct { + s struct{ s struct{ i int } } + } + var s2, s3 struct { + a struct{ i int } + b int + } + func() { + i = 1 + 2*i + s3.a.i + func() int { + s2.a, s2.b = s3.a, s3.b + return 0 + }() + func(*int) int { + return s1.s.s.i + }(new(int)) + }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49512.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49512.go new file mode 100644 index 0000000000000000000000000000000000000000..597aec84860f80e5b69a2a3ae4b60fa33897eca7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49512.go @@ -0,0 +1,54 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type S struct{ + m1Called, m2Called bool +} + +func (s *S) M1(int) (int, int) { + s.m1Called = true + return 0, 0 +} + +func (s *S) M2(int) (int, int) { + s.m2Called = true + return 0, 0 +} + +type C struct { + calls []func(int) (int, int) +} + +func makeC() Funcs { + return &C{} +} + +func (c *C) Add(fn func(int) (int, int)) Funcs { + c.calls = append(c.calls, fn) + return c +} + +func (c *C) Call() { + for _, fn := range c.calls { + fn(0) + } +} + +type Funcs interface { + Add(func(int) (int, int)) Funcs + Call() +} + +func main() { + s := &S{} + c := makeC().Add(s.M1).Add(s.M2) + c.Call() + if !s.m1Called || !s.m2Called { + panic("missed method call") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49592.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49592.go new file mode 100644 index 0000000000000000000000000000000000000000..8b5612943a748097c256874f14930d3548d9109f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49592.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func _() { + var x *interface{} + var y interface{} + _ = x == y +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49611.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49611.go new file mode 100644 index 0000000000000000000000000000000000000000..b40ad5864954d7cecb091484fc3d0a3e0c0fb886 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49611.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + var () +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49619.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49619.go new file mode 100644 index 0000000000000000000000000000000000000000..c9f3cbc4ad38de09ca08df53ab2a78a2a725d169 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49619.go @@ -0,0 +1,19 @@ +// build + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This testcase caused a linker crash in DWARF generation. + +package main + +//go:noinline +func f() any { + var a []any + return a[0] +} + +func main() { + f() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue4964.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue4964.go new file mode 100644 index 0000000000000000000000000000000000000000..8291d1bb97d43d0dd7b54b6696abf1f971f77406 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue4964.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4964: exported escape analysis result is not enough +// for cross package analysis. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.go new file mode 100644 index 0000000000000000000000000000000000000000..c6c22a1b4e9ec07ca3ca0240366bcd3458811944 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.go @@ -0,0 +1,18 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +var x any +var y interface{} + +var _ = &x == &y // assert x and y have identical types + +func main() { + fmt.Printf("%T\n%T\n", &x, &y) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.out new file mode 100644 index 0000000000000000000000000000000000000000..bd06d717cf4a788e0fd7b880e401c8999d3f62d0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49665.out @@ -0,0 +1,2 @@ +*interface {} +*interface {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49767.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49767.go new file mode 100644 index 0000000000000000000000000000000000000000..e25081dc9355ac86c52b6d5388d488508df491b8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49767.go @@ -0,0 +1,12 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + ch := make(chan struct{ v [65536]byte }) // ERROR "channel element type too large" + close(ch) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue49814.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue49814.go new file mode 100644 index 0000000000000000000000000000000000000000..067ce42b7629c45c3a3a2c3ff13a12775e94b723 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue49814.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// "must be integer" error is for 32-bit architectures +type V [1 << 50]byte // ERROR "larger than address space|invalid array length" + +var X [1 << 50]byte // ERROR "larger than address space|invalid array length" + +func main() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5002.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5002.go new file mode 100644 index 0000000000000000000000000000000000000000..5ac119a2b28159108fa25f76c5abfca4227465ed --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5002.go @@ -0,0 +1,16 @@ +// build + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5002: 8g produces invalid CMPL $0, $0. +// Used to fail at link time. + +package main + +func main() { + var y int64 + if y%1 == 0 { + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50169.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50169.go new file mode 100644 index 0000000000000000000000000000000000000000..30d2713ec9919b1fffb53638444f1a26328254cf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50169.go @@ -0,0 +1,24 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var x Value + NewScanner().Scan(x) +} + +type Value any + +type Scanner interface{ Scan(any) error } + +func NewScanner() Scanner { + return &t{} +} + +type t struct{} + +func (*t) Scan(interface{}) error { return nil } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50190.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50190.go new file mode 100644 index 0000000000000000000000000000000000000000..a5ee646a1aa8d4df09f7fc2eb6ad86f2064902c1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50190.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Int = int + +type A = struct{ int } +type B = struct{ Int } + +func main() { + var x, y interface{} = A{}, B{} + if x == y { + panic("FAIL") + } + + { + type C = int32 + x = struct{ C }{} + } + { + type C = uint32 + y = struct{ C }{} + } + if x == y { + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50372.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50372.go new file mode 100644 index 0000000000000000000000000000000000000000..116d843694a8286f694ff4bef11e0c56db961c38 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50372.go @@ -0,0 +1,29 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func _(s []int) { + var i, j, k, l int + _, _, _, _ = i, j, k, l + + for range s {} + for i = range s {} + for i, j = range s {} + for i, j, k = range s {} // ERROR "range clause permits at most two iteration variables" + for i, j, k, l = range s {} // ERROR "range clause permits at most two iteration variables" +} + +func _(s chan int) { + var i, j, k, l int + _, _, _, _ = i, j, k, l + + for range s {} + for i = range s {} + for i, j = range s {} // ERROR "range over .* permits only one iteration variable" + for i, j, k = range s {} // ERROR "range over .* permits only one iteration variable" + for i, j, k, l = range s {} // ERROR "range over .* permits only one iteration variable" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50439.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50439.go new file mode 100644 index 0000000000000000000000000000000000000000..63629a5bde986b1882d864161a3a03c7e38b3c30 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50439.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var data []struct { + F string `tag` +} + +var V = ([]struct{ F string })(data) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5056.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5056.go new file mode 100644 index 0000000000000000000000000000000000000000..6fb444aa67958e1d5c791126d8c91e53a2d32ad1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5056.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5056: escape analysis not applied to wrapper functions + +package main + +type Foo int16 + +func (f Foo) Esc() *int{ + x := int(f) + return &x +} + +type iface interface { + Esc() *int +} + +var bar, foobar *int + +func main() { + var quux iface + var x Foo + + quux = x + bar = quux.Esc() + foobar = quux.Esc() + if bar == foobar { + panic("bar == foobar") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50671.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50671.go new file mode 100644 index 0000000000000000000000000000000000000000..9f4742bfcdcde352055fb15406dc818b9914b4bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50671.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 50671: sign extension eliminated incorrectly on MIPS64. + +package main + +//go:noinline +func F(x int32) (float64, int64) { + a := float64(x) + b := int64(x) + return a, b +} + +var a, b, c float64 + +// Poison some floating point registers with non-zero high bits. +// +//go:noinline +func poison(x float64) { + a = x - 123.45 + b = a * 1.2 + c = b + 3.4 +} + +func main() { + poison(333.3) + _, b := F(123) + if b != 123 { + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50672.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50672.go new file mode 100644 index 0000000000000000000000000000000000000000..178786a104912119bfb5f982bf8cbb4b5f7bacd4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50672.go @@ -0,0 +1,105 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var ok = false + +func f() func(int, int) int { + ok = true + return func(int, int) int { return 0 } +} + +func g() (int, int) { + if !ok { + panic("FAIL") + } + return 0, 0 +} + +var _ = f()(g()) + +func main() { + f1() + f2() + f3() + f4() +} + +func f1() { + ok := false + + f := func() func(int, int) { + ok = true + return func(int, int) {} + } + g := func() (int, int) { + if !ok { + panic("FAIL") + } + return 0, 0 + } + + f()(g()) +} + +type S struct{} + +func (S) f(int, int) {} + +func f2() { + ok := false + + f := func() S { + ok = true + return S{} + } + g := func() (int, int) { + if !ok { + panic("FAIL") + } + return 0, 0 + } + + f().f(g()) +} + +func f3() { + ok := false + + f := func() []func(int, int) { + ok = true + return []func(int, int){func(int, int) {}} + } + g := func() (int, int) { + if !ok { + panic("FAIL") + } + return 0, 0 + } + f()[0](g()) +} + +type G[T any] struct{} + +func (G[T]) f(int, int) {} + +func f4() { + ok := false + + f := func() G[int] { + ok = true + return G[int]{} + } + g := func() (int, int) { + if !ok { + panic("FAIL") + } + return 0, 0 + } + + f().f(g()) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50788.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50788.go new file mode 100644 index 0000000000000000000000000000000000000000..24d0eb002a3e762db87328399ca516946f1265f6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50788.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue50854.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue50854.go new file mode 100644 index 0000000000000000000000000000000000000000..a5be9195f11bd453099650b8ff7fd7a53148c3a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue50854.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// This checks for incorrect application of CMP(-x,y) -> CMN(x,y) in arm and arm64 + +//go:noinline +func f(p int64, x, y int64) bool { return -x <= p && p <= y } + +//go:noinline +func g(p int32, x, y int32) bool { return -x <= p && p <= y } + +// There are some more complicated patterns involving compares and shifts, try to trigger those. + +//go:noinline +func h(p int64, x, y int64) bool { return -(x<<1) <= p && p <= y } + +//go:noinline +func k(p int32, x, y int32) bool { return -(1< 50 { + + } + } +} + +func main() { // GC_ERROR "stack frame too large" + defer f() + g() +} + +func f() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52701.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52701.go new file mode 100644 index 0000000000000000000000000000000000000000..f1de16c972f32ab96d88fc8da7930b7b4eacfff9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52701.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T1 struct{} +type T2 struct{} + +func f() { + switch (T1{}) { + case T1(T2{}): + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52748.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52748.go new file mode 100644 index 0000000000000000000000000000000000000000..e9f7ea0510e7cdd53cf339f3a4ef0f28d29370f6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52748.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +type S[T any] struct{} + +const c = unsafe.Sizeof(S[[c]byte]{}) // ERROR "initialization cycle" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52788.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788.go new file mode 100644 index 0000000000000000000000000000000000000000..b0d7d142fc25de1d3d9e565695ddbd3d35adcd66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52788: miscompilation for boolean comparison on ARM64. + +package main + +import ( + "fmt" + "reflect" +) + +func f(next func() bool) { + for b := next(); b; b = next() { + fmt.Printf("next() returned %v\n", b) + } +} + +func main() { + next := reflect.MakeFunc(reflect.TypeOf((func() bool)(nil)), func(_ []reflect.Value) []reflect.Value { + return []reflect.Value{reflect.ValueOf(false)} + }) + reflect.ValueOf(f).Call([]reflect.Value{next}) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.go new file mode 100644 index 0000000000000000000000000000000000000000..38b8416150c924fb697bd54862d5caee60a89032 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52788: miscompilation for boolean ops on ARM64. + +package main + +import ( + "fmt" + "reflect" + "os" +) + +func f(next func() bool) { + for b := next(); b; b = next() { + fmt.Printf("%v\n", b) + os.Exit(0) + } +} + +func main() { + next := reflect.MakeFunc(reflect.TypeOf((func() bool)(nil)), func(_ []reflect.Value) []reflect.Value { + return []reflect.Value{reflect.ValueOf(true)} + }) + reflect.ValueOf(f).Call([]reflect.Value{next}) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.out new file mode 100644 index 0000000000000000000000000000000000000000..27ba77ddaf61532f217964734769a42cdabc17dc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52788a.out @@ -0,0 +1 @@ +true diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52841.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52841.go new file mode 100644 index 0000000000000000000000000000000000000000..c8632aef778547c6209b0e413be28be03d380ef3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52841.go @@ -0,0 +1,30 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52841: gofrontend crashed writing export data + +package p + +func F() { + x := ([17][1]interface { + Method9() + Method10() + }{ + func() (V47 [1]interface { + Method9() + Method10() + }) { + return + }(), + func(V48 string) (V49 [1]interface { + Method9() + Method10() + }) { + return + }("440"), + }) + _ = x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52846.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52846.go new file mode 100644 index 0000000000000000000000000000000000000000..747fc885b4589aeaa6bcfd9e04b1b4a8782a87a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52846.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52846: gofrontend crashed with alias as map key type + +package p + +type S struct { + F string +} + +type A = S + +var M = map[A]int{A{""}: 0} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52856.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52856.go new file mode 100644 index 0000000000000000000000000000000000000000..1991aaa408fde1e92ed0cee024f5bdc9f2e4c406 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52856.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that an embedded unexported type has a different name in +// different packages. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52862.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52862.go new file mode 100644 index 0000000000000000000000000000000000000000..322d5f6c4950d28e4674271bad8bd6e292a62b9f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52862.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// gofrontend crash importing a complex zero value. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52870.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52870.go new file mode 100644 index 0000000000000000000000000000000000000000..a1c441a77d624678a7c90f42bc9b2b490a7395bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52870.go @@ -0,0 +1,27 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52870: gofrontend gave incorrect error when incorrectly +// compiling ambiguous promoted method. + +package p + +type S1 struct { + *S2 +} + +type S2 struct { + T3 + T4 +} + +type T3 int32 + +func (T3) M() {} + +type T4 int32 + +func (T4) M() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52871.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52871.go new file mode 100644 index 0000000000000000000000000000000000000000..d3731a183afd5d34193dd5436fe8b1c121aec80f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52871.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// gofrontend crashed compiling this code. + +package p + +type S struct {} + +func (s *S) test(_ string) {} + +var T = [1]func(*S, string) { + (*S).test, +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52907.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52907.go new file mode 100644 index 0000000000000000000000000000000000000000..f54b2049eb9a4b94afa47c5dc9b0cc04851fd62c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52907.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T int](t T) { + for true { + func() { + t = func() T { return t }() + }() + } +} + +func g[T int](g T) { + for true { + _ = func() T { return func(int) T { return g }(0) }() + } +} + +func main() { + f(0) + g(0) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5291.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5291.go new file mode 100644 index 0000000000000000000000000000000000000000..00d2ada4cc8e547b2e2137b1f1fce5b151f7bc0e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5291.go @@ -0,0 +1,9 @@ +// rundir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5291: GC crash + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue52953.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue52953.go new file mode 100644 index 0000000000000000000000000000000000000000..2085e4e3fe36ec11998d556ad5ad7f739fa693ff --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue52953.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 52953: miscompilation for composite literal assignment +// when LHS is address-taken. + +package main + +type T struct { + Field1 bool +} + +func main() { + var ret T + ret.Field1 = true + var v *bool = &ret.Field1 + ret = T{Field1: *v} + check(ret.Field1) +} + +//go:noinline +func check(b bool) { + if !b { + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53018.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53018.go new file mode 100644 index 0000000000000000000000000000000000000000..439d9d58c13605534f86d668bcad6d2aaf26d30c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53018.go @@ -0,0 +1,30 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var V []int + +func f(i int, c chan int) int { + arr := []int{0, 1} + for range c { + for a2 := range arr { + var a []int + V = V[:1/a2] + a[i] = 0 + } + return func() int { + arr = []int{} + return func() int { + return func() int { + return func() int { return 4 }() + }() + }() + }() + } + + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53137.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53137.go new file mode 100644 index 0000000000000000000000000000000000000000..a0e67211ce5be53dc55d5cc9ea557de7468fa3db --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53137.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "unsafe" +) + +type Embedded struct { + B int +} + +type S[K any] struct { + A K + Embedded +} + +func showOffsets[K any](d *S[K]) { + o1 := unsafe.Offsetof(d.B) + o2 := unsafe.Offsetof(d.Embedded) + if o1 != o2 { + panic("offset mismatch") + } +} + +func main() { + showOffsets(new(S[int])) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53309.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53309.go new file mode 100644 index 0000000000000000000000000000000000000000..4ad88d4753a27a7d3772fd1566ec7f839d070462 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53309.go @@ -0,0 +1,42 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type TaskInput interface { + deps() []*taskDefinition +} + +type Value[T any] interface { + metaValue +} + +type metaValue interface { + TaskInput +} + +type taskDefinition struct { +} + +type taskResult struct { + task *taskDefinition +} + +func (tr *taskResult) deps() []*taskDefinition { + return nil +} + +func use[T any](v Value[T]) { + _, ok := v.(*taskResult) + if !ok { + panic("output must be *taskResult") + } +} + +func main() { + tr := &taskResult{&taskDefinition{}} + use[string](Value[string](tr)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53439.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53439.go new file mode 100644 index 0000000000000000000000000000000000000000..f366a44183fd3b2c505213b256af30ba033ede0f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53439.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +func F[T int](v T) uintptr { + return unsafe.Offsetof(struct{ f T }{ + func(T) T { return v }(v), + }.f) +} + +func f() { + F(1) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53454.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53454.go new file mode 100644 index 0000000000000000000000000000000000000000..8b16d8183988bbf59cd5d1bc1c99e5d7bfe115d7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53454.go @@ -0,0 +1,89 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T1 struct { + A T5 + B T2 + C T7 + D T4 +} + +type T2 struct { + T3 + A float64 + E float64 + C float64 +} + +type T3 struct { + F float64 + G float64 + H float64 + I float64 + J float64 + K float64 + L float64 +} + +type T4 struct { + M float64 + N float64 + O float64 + P float64 +} + +type T5 struct { + Q float64 + R float64 + S float64 + T float64 + U float64 + V float64 +} + +type T6 struct { + T9 + C T10 +} + +type T7 struct { + T10 + T11 +} + +type T8 struct { + T9 + C T7 +} + +type T9 struct { + A T5 + B T3 + D T4 +} + +type T10 struct { + W float64 +} + +type T11 struct { + X float64 + Y float64 +} + +func MainTest(x T1, y T8, z T6) float64 { + return Test(x.B, x.A, x.D, x.C, y.B, y.A, y.D, y.C, z.B, z.A, z.D, + T7{ + T10: T10{ + W: z.C.W, + }, + T11: T11{}, + }, + ) +} +func Test(a T2, b T5, c T4, d T7, e T3, f T5, g T4, h T7, i T3, j T5, k T4, l T7) float64 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5358.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5358.go new file mode 100644 index 0000000000000000000000000000000000000000..cfe8a9242a734748b08151a1ccae1759b1ee8fe7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5358.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5358: incorrect error message when using f(g()) form on ... args. + +package main + +func f(x int, y ...int) {} + +func g() (int, []int) + +func main() { + f(g()) // ERROR "as int value in|incompatible type" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.go new file mode 100644 index 0000000000000000000000000000000000000000..ead40b57af50c5942201247a53661cfe74c96aaf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.go @@ -0,0 +1,53 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "math" + +func main() { + f() + g() + h() + j(math.MinInt64) +} +func f() { + for i := int64(math.MaxInt64); i <= math.MaxInt64; i++ { + if i < 0 { + println("done") + return + } + println(i, i < 0) + } +} +func g() { + for i := int64(math.MaxInt64) - 1; i <= math.MaxInt64; i++ { + if i < 0 { + println("done") + return + } + println(i, i < 0) + } +} +func h() { + for i := int64(math.MaxInt64) - 2; i <= math.MaxInt64; i += 2 { + if i < 0 { + println("done") + return + } + println(i, i < 0) + } +} + +//go:noinline +func j(i int64) { + for j := int64(math.MaxInt64); j <= i-1; j++ { + if j < 0 { + break + } + println(j) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.out new file mode 100644 index 0000000000000000000000000000000000000000..577b50fd2cdc07debd932fc7b3c7a5cb841183fd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53600.out @@ -0,0 +1,9 @@ +9223372036854775807 false +done +9223372036854775806 false +9223372036854775807 false +done +9223372036854775805 false +9223372036854775807 false +done +9223372036854775807 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53619.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53619.go new file mode 100644 index 0000000000000000000000000000000000000000..2b6d047d339cf475acd992f38eebcc7582542928 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53619.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var c = b +var d = a + +var a, b any = any(nil).(bool) + +func main() { + if c != false { + panic(c) + } + if d != false { + panic(d) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53635.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53635.go new file mode 100644 index 0000000000000000000000000000000000000000..bea54938055d1e236a2ffeac83427c3a5b04667c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53635.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + f[int]() +} + +func f[T any]() { + switch []T(nil) { + case nil: + default: + panic("FAIL") + } + + switch (func() T)(nil) { + case nil: + default: + panic("FAIL") + } + + switch (map[int]T)(nil) { + case nil: + default: + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.go new file mode 100644 index 0000000000000000000000000000000000000000..555f7da5282c062ab7546a257f136db62d8b1128 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.go @@ -0,0 +1,42 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "math" + +func main() { + f() + g() + h() +} +func f() { + for i := int64(math.MinInt64); i >= math.MinInt64; i-- { + if i > 0 { + println("done") + return + } + println(i, i > 0) + } +} +func g() { + for i := int64(math.MinInt64) + 1; i >= math.MinInt64; i-- { + if i > 0 { + println("done") + return + } + println(i, i > 0) + } +} +func h() { + for i := int64(math.MinInt64) + 2; i >= math.MinInt64; i -= 2 { + if i > 0 { + println("done") + return + } + println(i, i > 0) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.out new file mode 100644 index 0000000000000000000000000000000000000000..f699392cf3fe06504b2e7e8163038fa7d0b6f5ef --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53653.out @@ -0,0 +1,8 @@ +-9223372036854775808 false +done +-9223372036854775807 false +-9223372036854775808 false +done +-9223372036854775806 false +-9223372036854775808 false +done diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53702.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53702.go new file mode 100644 index 0000000000000000000000000000000000000000..0b251c2d7be969ba13253c14a403b9b345f64693 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53702.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Elem struct{} + +func (*Elem) Wait(callback func()) {} + +type Base struct { + elem [8]*Elem +} + +var g_val = 1 + +func (s *Base) Do() *int { + resp := &g_val + for _, e := range s.elem { + e.Wait(func() { + *resp = 0 + }) + } + return resp +} + +type Sub struct { + *Base +} + +func main() { + a := Sub{new(Base)} + resp := a.Do() + if resp != nil && *resp != 1 { + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5373.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5373.go new file mode 100644 index 0000000000000000000000000000000000000000..8aee9a2c7813edca61b67c91e2a4ada3484b6675 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5373.go @@ -0,0 +1,71 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Ensure that zeroing range loops have the requisite side-effects. + +package main + +import ( + "fmt" + "os" +) + +func check(n int) { + // When n == 0, i is untouched by the range loop. + // Picking an initial value of -1 for i makes the + // "want" calculation below correct in all cases. + i := -1 + s := make([]byte, n) + for i = range s { + s[i] = 0 + } + if want := n - 1; i != want { + fmt.Printf("index after range with side-effect = %d want %d\n", i, want) + os.Exit(1) + } + + i = n + 1 + // i is shadowed here, so its value should be unchanged. + for i := range s { + s[i] = 0 + } + if want := n + 1; i != want { + fmt.Printf("index after range without side-effect = %d want %d\n", i, want) + os.Exit(1) + } + + // Index variable whose evaluation has side-effects + var x int + f := func() int { + x++ + return 0 + } + var a [1]int + for a[f()] = range s { + s[a[f()]] = 0 + } + if want := n * 2; x != want { + fmt.Printf("index function calls = %d want %d\n", x, want) + os.Exit(1) + } + + // Range expression whose evaluation has side-effects + x = 0 + b := [1][]byte{s} + for i := range b[f()] { + b[f()][i] = 0 + } + if want := n + 1; x != n+1 { + fmt.Printf("range expr function calls = %d want %d\n", x, want) + os.Exit(1) + } +} + +func main() { + check(0) + check(1) + check(15) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue53982.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue53982.go new file mode 100644 index 0000000000000000000000000000000000000000..512b1af2bca1f6adbf090fb650584d7144cd1ac9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue53982.go @@ -0,0 +1,25 @@ +// build + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type S[K, V any] struct { + E[V] +} + +type E[K any] struct{} + +func (e E[K]) M() E[K] { + return e +} + +func G[K, V any](V) { + _ = (*S[K, V]).M +} + +func main() { + G[*int](new(int)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54159.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54159.go new file mode 100644 index 0000000000000000000000000000000000000000..8ef0e684837edda5cfe76168b52457a449f3b97a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54159.go @@ -0,0 +1,22 @@ +// errorcheck -0 -m=2 + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func run() { // ERROR "cannot inline run: recursive" + f := func() { // ERROR "can inline run.func1 with cost .* as:.*" "func literal does not escape" + g() // ERROR "inlining call to g" + } + f() // ERROR "inlining call to run.func1" "inlining call to g" + run() +} + +func g() { // ERROR "can inline g with cost .* as:.*" +} + +func main() { // ERROR "can inline main with cost .* as:.*" + run() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54220.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54220.go new file mode 100644 index 0000000000000000000000000000000000000000..105f6e909840f58cac2f40f1ab95254fb849ddf8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54220.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "strconv" + "sync/atomic" + "unsafe" +) + +type t struct { + i1 atomic.Int32 + i2 atomic.Int64 +} + +var v t + +func main() { + if o := unsafe.Offsetof(v.i2); o != 8 { + panic("unexpected offset, want: 8, got: " + strconv.Itoa(int(o))) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54280.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54280.go new file mode 100644 index 0000000000000000000000000000000000000000..4f9103d4e6060ddf7a6c6fef409721a4de3d6956 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54280.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Don't crash in export of oversized integer constant. + +package p + +const C = 912_345_678_901_234_567_890_123_456_789_012_345_678_901_234_567_890_912_345_678_901_234_567_890_123_456_789_012_345_678_901_234_567_890_912_345_678_901_234_567_890_123_456_789_012_345_678_901_234_567_890_912 // ERROR "constant overflow" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54307.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54307.go new file mode 100644 index 0000000000000000000000000000000000000000..342a53af84506ea223a1e8aa73aed232e91eb2e3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54307.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f[Int int, Uint uint]() { + _ = uint(Int(-1)) + _ = uint(Uint(0) - 1) +} + +func g[String string]() { + _ = String("")[100] +} + +var _ = f[int, uint] +var _ = g[string] diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54343.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54343.go new file mode 100644 index 0000000000000000000000000000000000000000..10b91a5398d572b53a53a19d3196bedc364efadf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54343.go @@ -0,0 +1,45 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "runtime" + +func main() { + if wait() { + panic("GC'd early") + } + m = nil + if !wait() { + panic("never GC'd") + } +} + +var m = New[int]().M + +func New[X any]() *T[X] { + p := new(T[X]) + runtime.SetFinalizer(p, func(*T[X]) { close(done) }) + return p +} + +type T[X any] [4]int // N.B., [4]int avoids runtime's tiny object allocator + +func (*T[X]) M() {} + +var done = make(chan int) + +func wait() bool { + for i := 0; i < 10; i++ { + runtime.GC() + select { + case <-done: + return true + default: + } + } + return false +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54348.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54348.go new file mode 100644 index 0000000000000000000000000000000000000000..15b2f758efddb38655ab51d31ac33c13ddca79c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54348.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + F[T[int]]() +} + +func F[X interface{ M() }]() { + var x X + x.M() +} + +type T[X any] struct{ E } + +type E struct{} + +func (h E) M() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54467.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54467.go new file mode 100644 index 0000000000000000000000000000000000000000..42e221c95412646f5f68aae72bcf49bffaa529f0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54467.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func main() { + var x [64]byte + for i := range x { + x[i] = byte(i) + } + y := x + + copy(x[4:36], x[2:34]) + *(*[32]byte)(y[4:36]) = *(*[32]byte)(y[2:34]) + + for i := range x { + if x[i] != y[i] { + fmt.Printf("x[%v] = %v; y[%v] = %v\n", i, x[i], i, y[i]) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54632.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54632.go new file mode 100644 index 0000000000000000000000000000000000000000..0d4e32f28f1ee909e56eb8c3040f5734c6d4e26b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54632.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The inliner would erroneously scan the caller function's body for +// reassignments *before* substituting the inlined function call body, +// which could cause false positives in deciding when it's safe to +// transitively inline indirect function calls. + +package main + +func main() { + bug1() + bug2(fail) +} + +func bug1() { + fn := fail + fn = pass + fn() +} + +func bug2(fn func()) { + fn = pass + fn() +} + +func pass() {} +func fail() { panic("FAIL") } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54638.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54638.go new file mode 100644 index 0000000000000000000000000000000000000000..d0258b0c6881ce884d848dd5c9f0b29236b2f473 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54638.go @@ -0,0 +1,40 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 54638: composite literal assignment with +// alignment > PtrSize causes ICE. + +package p + +import "sync/atomic" + +type S struct{ l any } + +type T struct { + H any + a [14]int64 + f func() + x atomic.Int64 +} + +//go:noinline +func (T) M(any) {} + +type W [2]int64 + +//go:noinline +func (W) Done() {} + +func F(l any) [3]*int { + var w W + var x [3]*int // use some stack + t := T{H: S{l: l}} + go func() { + t.M(l) + w.Done() + }() + return x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5470.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5470.go new file mode 100644 index 0000000000000000000000000000000000000000..6123c0983a8159acda04f306f774efee0d9bc538 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5470.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5470: exported data for inlining may miss +// the type argument of make. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54722.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54722.go new file mode 100644 index 0000000000000000000000000000000000000000..7de27082b188ac441b36eceb3ac73532c7fd4609 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54722.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type G[T any] struct { + h H[G[T]] +} + +type H[T any] struct{} + +var x G[int] diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54722b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54722b.go new file mode 100644 index 0000000000000000000000000000000000000000..a6c8f829ab68654419ece038f53e62f4e0aeb8bc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54722b.go @@ -0,0 +1,30 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type value[V comparable] struct { + node *node[value[V]] + value V +} + +type node[V comparable] struct { + index *index[V] + children map[string]*node[V] +} + +type index[V comparable] struct { + arrays []array[V] +} + +type array[V comparable] struct { + valueMap map[int]V +} + +var x value[int] +var y value[*Column] + +type Column struct{ column int } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54911.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54911.go new file mode 100644 index 0000000000000000000000000000000000000000..dee24da0bdb30d9bd8aa54a2f780134b47e6fb29 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54911.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Set[T comparable] map[T]struct{} + +func (s Set[T]) Add() Set[T] { + return s +} + +func (s Set[T]) Copy() Set[T] { + return Set[T].Add(s) +} + +func main() { + _ = Set[int]{42: {}} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54912.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54912.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54912.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5493.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5493.go new file mode 100644 index 0000000000000000000000000000000000000000..8f771bc2db369c9baa9d80cd773c1d62d1cc0225 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5493.go @@ -0,0 +1,58 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "runtime" + "sync" + "sync/atomic" + "time" +) + +const N = 10 + +var count int64 + +func run() error { + f1 := func() {} + f2 := func() { + func() { + f1() + }() + } + runtime.SetFinalizer(&f1, func(f *func()) { + atomic.AddInt64(&count, -1) + }) + go f2() + return nil +} + +func main() { + // Does not work with gccgo, due to partially conservative GC. + // Try to enable when we have fully precise GC. + if runtime.Compiler == "gccgo" { + return + } + count = N + var wg sync.WaitGroup + wg.Add(N) + for i := 0; i < N; i++ { + go func() { + run() + wg.Done() + }() + } + wg.Wait() + for i := 0; i < 2*N; i++ { + time.Sleep(10 * time.Millisecond) + runtime.GC() + } + if count != 0 { + println(count, "out of", N, "finalizer are not called") + panic("not all finalizers are called") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54959.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54959.go new file mode 100644 index 0000000000000000000000000000000000000000..90524ce1866625b98e509a7f8ea2fc7bceb647f4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54959.go @@ -0,0 +1,16 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var p *int + +func main() { + var i int + p = &i // escape i to keep the compiler from making the closure trivial + + func() { i++ }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue54991.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue54991.go new file mode 100644 index 0000000000000000000000000000000000000000..9ab0f5d06cf653408384592d29f5bf867d0dc043 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue54991.go @@ -0,0 +1,29 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import ( + "sync/atomic" +) + +type I interface { + M() +} + +type S struct{} + +func (*S) M() {} + +type T struct { + I + x atomic.Int64 +} + +func F() { + t := &T{I: &S{}} + t.M() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue55122.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue55122.go new file mode 100644 index 0000000000000000000000000000000000000000..24da89dcb6d31fb692df9967058d6b15b9219d70 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue55122.go @@ -0,0 +1,42 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for i := 0; i < 10000; i++ { + h(i) + sink = make([]byte, 1024) // generate some garbage + } +} + +func h(iter int) { + var x [32]byte + for i := 0; i < 32; i++ { + x[i] = 99 + } + g(&x) + if x == ([32]byte{}) { + return + } + for i := 0; i < 32; i++ { + println(x[i]) + } + panic(iter) +} + +//go:noinline +func g(x interface{}) { + switch e := x.(type) { + case *[32]byte: + var c [32]byte + *e = c + case *[]byte: + *e = nil + } +} + +var sink []byte diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue55122b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue55122b.go new file mode 100644 index 0000000000000000000000000000000000000000..a911a9f1b6aa562c485356addef0d127096d4f18 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue55122b.go @@ -0,0 +1,43 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for i := 0; i < 10000; i++ { + h(i) + sink = make([]byte, 1024) // generate some garbage + } +} + +func h(iter int) { + var x [32]byte + for i := 0; i < 32; i++ { + x[i] = 99 + } + g(&x) + if x == ([32]byte{}) { + return + } + for i := 0; i < 32; i++ { + println(x[i]) + } + panic(iter) +} + +//go:noinline +func g(x interface{}) { + switch e := x.(type) { + case *[32]byte: + var c [32]byte + *e = c + case *[3]*byte: + var c [3]*byte + *e = c + } +} + +var sink []byte diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5515.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5515.go new file mode 100644 index 0000000000000000000000000000000000000000..053abf6f7cffa18bdf000cc96efd086f405e4a2e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5515.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5515: miscompilation doing inlining in generated method wrapper + +package main + +type T uint32 + +func main() { + b := make([]T, 8) + b[0] = 0xdeadbeef + rs := Slice(b) + sort(rs) +} + +type Slice []T + +func (s Slice) Swap(i, j int) { + tmp := s[i] + s[i] = s[j] + s[j] = tmp +} + +type Interface interface { + Swap(i, j int) +} + +func sort(data Interface) { + data.Swap(0, 4) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue55242.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue55242.go new file mode 100644 index 0000000000000000000000000000000000000000..4b29eb815cdaaeba06c194e9b0e3edc408e632f1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue55242.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 55242: gofrontend crash calling function that returns +// trailing empty struct. + +package p + +func F1() (int, struct{}) { + return 0, struct{}{} +} + +func F2() { + F1() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5581.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5581.go new file mode 100644 index 0000000000000000000000000000000000000000..8834b4453d8a2d8dd403e8594ed800f53928a817 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5581.go @@ -0,0 +1,34 @@ +// errorcheck + +// Used to emit a spurious "invalid recursive type" error. +// See golang.org/issue/5581. + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func NewBar() *Bar { return nil } + +func (x *Foo) Method() (int, error) { + for y := range x.m { + _ = y.A + } + return 0, nil +} + +type Foo struct { + m map[*Bar]int +} + +type Bar struct { + A *Foo + B chan Blah // ERROR "undefined.*Blah" +} + +func main() { + fmt.Println("Hello, playground") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue55889.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue55889.go new file mode 100644 index 0000000000000000000000000000000000000000..68812c2157b851dc273580136985ef80cf3af7c6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue55889.go @@ -0,0 +1,21 @@ +// errorcheck -0 -lang=go1.17 + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Prior to Go 1.18, ineffectual //go:linkname directives were treated +// as noops. Ensure that modules that contain these directives (e.g., +// x/sys prior to go.dev/cl/274573) continue to compile. + +package p + +import _ "unsafe" + +//go:linkname nonexistent nonexistent + +//go:linkname constant constant +const constant = 42 + +//go:linkname typename typename +type typename int diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5607.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5607.go new file mode 100644 index 0000000000000000000000000000000000000000..785be7a2c76153490c1b04c9149420058c4a18a3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5607.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5607: generation of init() function incorrectly +// uses initializers of blank variables inside closures. + +package main + +var Test = func() { + var mymap = map[string]string{"a": "b"} + + var innerTest = func() { + // Used to crash trying to compile this line as + // part of init() (funcdepth mismatch). + var _, x = mymap["a"] + println(x) + } + innerTest() +} + +var Test2 = func() { + // The following initializer should not be part of init() + // The compiler used to generate a call to Panic() in init(). + var _, x = Panic() + _ = x +} + +func Panic() (int, int) { + panic("omg") + return 1, 2 +} + +func main() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5609.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5609.go new file mode 100644 index 0000000000000000000000000000000000000000..43ad1857784b5efd5c2cb7927a504bec66b3fd70 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5609.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5609: overflow when calculating array size + +package pkg + +const Large uint64 = 18446744073709551615 + +var foo [Large]uint64 // ERROR "array bound is too large|array bound overflows|invalid array length" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56103.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56103.go new file mode 100644 index 0000000000000000000000000000000000000000..54c28bfb55dea9b12710908e921c00c5bcf824f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56103.go @@ -0,0 +1,46 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +// Self recursion. +type i interface{ m() interface{ i } } // ERROR "invalid recursive type" +type _ interface{ i } // no redundant error + +// Mutual recursion. +type j interface{ m() interface{ k } } // ERROR "invalid recursive type" +type k interface{ m() interface{ j } } + +// Both self and mutual recursion. +type ( + a interface { // ERROR "invalid recursive type" + m() interface { + a + b + } + } + b interface { + m() interface { + a + b + } + } +) + +// Self recursion through other types. +func _() { type i interface{ m() *interface{ i } } } // ERROR "invalid recursive type" +func _() { type i interface{ m() []interface{ i } } } // ERROR "invalid recursive type" +func _() { type i interface{ m() [0]interface{ i } } } // ERROR "invalid recursive type" +func _() { type i interface{ m() chan interface{ i } } } // ERROR "invalid recursive type" +func _() { type i interface{ m() map[interface{ i }]int } } // ERROR "invalid recursive type" +func _() { type i interface{ m() map[int]interface{ i } } } // ERROR "invalid recursive type" +func _() { type i interface{ m() func(interface{ i }) } } // ERROR "invalid recursive type" +func _() { type i interface{ m() func() interface{ i } } } // ERROR "invalid recursive type" +func _() { + type i interface { // ERROR "invalid recursive type" + m() struct{ i interface{ i } } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56105.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56105.go new file mode 100644 index 0000000000000000000000000000000000000000..ecbe26580730690a2f58ac36be3d24817fbfdb20 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56105.go @@ -0,0 +1,11 @@ +// compile -d=libfuzzer + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + _ = [...][]int{{}, {}, {}, {}, {}} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56109.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56109.go new file mode 100644 index 0000000000000000000000000000000000000000..68e09b1332c9597da30aba8e67f4f7ee21c68f36 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56109.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "math" + +func main() { + f := func(p bool) { + if p { + println("hi") + } + } + go f(true || math.Sqrt(2) > 1) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5614.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5614.go new file mode 100644 index 0000000000000000000000000000000000000000..f2518d2a0c160bde81b05094a1d5947dca9cc473 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5614.go @@ -0,0 +1,11 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5614: exported data for inlining may miss +// named types when used in implicit conversion to +// their underlying type. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56141.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56141.go new file mode 100644 index 0000000000000000000000000000000000000000..7430b85f44af42603c88246da6dc4110fa7259d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56141.go @@ -0,0 +1,12 @@ +// compile -d=libfuzzer + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(x, y int) { + _ = x > y + _ = y > x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56220.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56220.go new file mode 100644 index 0000000000000000000000000000000000000000..3cb5210e894a32b3301e7435822c671fb9dab256 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56220.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() int { + return int(1 - .0000001) // ERROR "cannot convert 1 - \.0000001 \(untyped float constant 0\.9999999\) to type int" +} + +func g() int64 { + return int64((float64(0.03) - float64(0.02)) * 1_000_000) // ERROR "cannot convert \(float64\(0\.03\) - float64\(0\.02\)\) \* 1_000_000 \(constant 9999\.999999999998 of type float64\) to type int64" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56280.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56280.go new file mode 100644 index 0000000000000000000000000000000000000000..1afbe9ebf7ffae3098e6728e49c62b0bdc1978c8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56280.go @@ -0,0 +1,7 @@ +// errorcheckdir -0 -m + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56727.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56727.go new file mode 100644 index 0000000000000000000000000000000000000000..af201c22a841247aedcf6ceb8a77e4bfe48b7797 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56727.go @@ -0,0 +1,45 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type I interface { + M() +} + +type S struct{} + +func (*S) M() {} + +type slice []I + +func f() { + ss := struct { + i I + }{ + i: &S{}, + } + + _ = [...]struct { + s slice + }{ + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56768.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56768.go new file mode 100644 index 0000000000000000000000000000000000000000..1b2db4cceb1a825c5e3f93c03d3c54895829e5e5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56768.go @@ -0,0 +1,37 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type I interface { + M() +} + +type slice []any + +func f() { + ss := struct{ i I }{} + + _ = [...]struct { + s slice + }{ + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + { + s: slice{ss.i}, + }, + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56777.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56777.go new file mode 100644 index 0000000000000000000000000000000000000000..8097ce9b02194b3a6701e00f8a89af0e425292dd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56777.go @@ -0,0 +1,56 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func fn(setText []rune, negate bool) int { + ranges := []singleRange{} + + if len(setText) > 0 { + fillFirst := false + l := len(setText) + if negate { + if setText[0] == 0 { + setText = setText[1:] + } else { + l++ + fillFirst = true + } + } + + if l%2 == 0 { + ranges = make([]singleRange, l/2) + } else { + ranges = make([]singleRange, l/2+1) + } + + first := true + if fillFirst { + ranges[0] = singleRange{first: 0} + first = false + } + + i := 0 + for _, r := range setText { + if first { + // lower bound in a new range + ranges[i] = singleRange{first: r} + first = false + } else { + ranges[i].last = r - 1 + i++ + first = true + } + } + } + + return len(ranges) +} + +type singleRange struct { + first rune + last rune +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56778.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56778.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56778.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56923.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56923.go new file mode 100644 index 0000000000000000000000000000000000000000..7cc9494b763c1d2fcdde1dcdceba77e6d693f597 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56923.go @@ -0,0 +1,27 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Eq[T any] interface { + Eqv(a T, b T) bool +} + +type EqFunc[T any] func(a, b T) bool + +func (r EqFunc[T]) Eqv(a, b T) bool { + return r(a, b) +} + +func New[T any](f func(a, b T) bool) Eq[T] { + return EqFunc[T](f) +} + +func Equal(a, b []byte) bool { + return string(a) == string(b) +} + +var Bytes Eq[[]byte] = New(Equal) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5698.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5698.go new file mode 100644 index 0000000000000000000000000000000000000000..081541cb87d90f5cc17c35ed964bd412e8e8065c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5698.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5698: can define a key type with slices. + +package main + +type Key struct { + a int16 // the compiler was confused by the padding. + b []int +} + +type Val struct{} + +type Map map[Key]Val // ERROR "invalid map key type" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.go new file mode 100644 index 0000000000000000000000000000000000000000..4fa6d759f9ebd681b45aac01633cf1d1c067b42a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.go @@ -0,0 +1,119 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "path/filepath" + "testing" +) + +var t *testing.T + +type TypeMeta struct { + Kind string + APIVersion string +} + +type ObjectMeta struct { + Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` + GenerateName string `json:"generateName,omitempty" protobuf:"bytes,2,opt,name=generateName"` + Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"` + SelfLink string `json:"selfLink,omitempty" protobuf:"bytes,4,opt,name=selfLink"` +} + +type ConfigSpec struct { + Disks []DiskSpec + StorageClass string +} + +type DiskSpec struct { + Name string + Size string + StorageClass string + Annotations map[string]string + VolumeName string +} + +// Config is the Schema for the configs API. +type Config struct { + TypeMeta + ObjectMeta + + Spec ConfigSpec +} + +func findDiskSize(diskSpec *DiskSpec, configSpec *ConfigSpec) string { + t.Log(fmt.Sprintf("Hello World")) + return diskSpec.Size +} + +func findStorageClassName(diskSpec *DiskSpec, configSpec *ConfigSpec) *string { + if diskSpec.StorageClass != "" { + return &diskSpec.StorageClass + } + + if configSpec != nil { + for _, d := range configSpec.Disks { + if d.Name == diskSpec.Name { + if d.StorageClass != "" { + return &d.StorageClass + } + break + } + } + + if configSpec.StorageClass != "" { + return &configSpec.StorageClass + } + } + return nil +} + +func Bar(config *Config) *ConfigSpec { + var configSpec *ConfigSpec + if config != nil { + configSpec = &config.Spec + } + return configSpec +} + +func Foo(diskSpec DiskSpec, config *Config) { + cs := Bar(config) + _ = findDiskSize(&diskSpec, cs) + cs = Bar(config) + _ = findStorageClassName(&diskSpec, cs) + +} + +func TestPanic(tt *testing.T) { + t = tt + myarray := []string{filepath.Join("..", "config", "crd", "bases")} + + for i := 0; i < 1000; i++ { + Foo(DiskSpec{ + Name: "DataDisk", + Size: "1Gi", + }, nil) + } + + t.Log(myarray) +} + +// Hack to run tests in a playground +func matchString(a, b string) (bool, error) { + return a == b, nil +} +func main() { + testSuite := []testing.InternalTest{ + { + Name: "TestPanic", + F: TestPanic, + }, + } + testing.Main(matchString, testSuite, nil, nil) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.out new file mode 100644 index 0000000000000000000000000000000000000000..7ef22e9a431ad0272713b71fdc8794016c8ef12f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue56990.out @@ -0,0 +1 @@ +PASS diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5704.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5704.go new file mode 100644 index 0000000000000000000000000000000000000000..11b9a93246cbad3ecaa04351d9198fb5393b1894 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5704.go @@ -0,0 +1,46 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5704: Conversions of empty strings to byte +// or rune slices return empty but non-nil slices. + +package main + +type ( + mystring string + mybytes []byte + myrunes []rune +) + +func checkBytes(s []byte, arg string) { + if len(s) != 0 { + panic("len(" + arg + ") != 0") + } + if s == nil { + panic(arg + " == nil") + } +} + +func checkRunes(s []rune, arg string) { + if len(s) != 0 { + panic("len(" + arg + ") != 0") + } + if s == nil { + panic(arg + " == nil") + } +} + +func main() { + checkBytes([]byte(""), `[]byte("")`) + checkBytes([]byte(mystring("")), `[]byte(mystring(""))`) + checkBytes(mybytes(""), `mybytes("")`) + checkBytes(mybytes(mystring("")), `mybytes(mystring(""))`) + + checkRunes([]rune(""), `[]rune("")`) + checkRunes([]rune(mystring("")), `[]rune(mystring(""))`) + checkRunes(myrunes(""), `myrunes("")`) + checkRunes(myrunes(mystring("")), `myrunes(mystring(""))`) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57184.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57184.go new file mode 100644 index 0000000000000000000000000000000000000000..1384b50be8779df1624128c301d1411f2c94a7d9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57184.go @@ -0,0 +1,40 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "log" + "reflect" + "sort" +) + +func main() { + const length = 257 + x := make([]int64, length) + for i := 0; i < length; i++ { + x[i] = int64(i) * 27644437 % int64(length) + } + + isLessStatic := func(i, j int) bool { + return x[i] < x[j] + } + + isLessReflect := reflect.MakeFunc(reflect.TypeOf(isLessStatic), func(args []reflect.Value) []reflect.Value { + i := args[0].Int() + j := args[1].Int() + b := x[i] < x[j] + return []reflect.Value{reflect.ValueOf(b)} + }).Interface().(func(i, j int) bool) + + sort.SliceStable(x, isLessReflect) + + for i := 0; i < length-1; i++ { + if x[i] >= x[i+1] { + log.Fatalf("not sorted! (length=%v, idx=%v)\n%v\n", length, i, x) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57309.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57309.go new file mode 100644 index 0000000000000000000000000000000000000000..ec6a397574aa652708bc1b758f7ae662669c3a2e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57309.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + M() +} + +type S struct { +} + +func (*S) M() { +} + +func main() { + func() { + I(&S{}).M() + }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5753.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5753.go new file mode 100644 index 0000000000000000000000000000000000000000..230a1e8c3bd403b74fb014a443625f081e4eed16 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5753.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5753: bad typecheck info causes escape analysis to +// not run on method thunks. + +package main + +type Thing struct{} + +func (t *Thing) broken(s string) []string { + foo := [1]string{s} + return foo[:] +} + +func main() { + t := &Thing{} + + f := t.broken + s := f("foo") + _ = f("bar") + if s[0] != "foo" { + panic(`s[0] != "foo"`) + } + +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5755.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5755.go new file mode 100644 index 0000000000000000000000000000000000000000..fa7ea4d204c897c08ea5ca8a5e3f276a31875938 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5755.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5755: exported data for inlining may miss +// named types when used in string conversions. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57778.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57778.go new file mode 100644 index 0000000000000000000000000000000000000000..597eb80fbd92ef08d3e00b834409b231e1895585 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57778.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type FreeListG[T any] struct { + freelist []*node[T] +} + +type node[T any] struct{} + +func NewFreeListG[T any](size int) *FreeListG[T] { + return &FreeListG[T]{freelist: make([]*node[T], 0, size)} +} + +var bf = NewFreeListG[*int](1024) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57823.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57823.go new file mode 100644 index 0000000000000000000000000000000000000000..d6708f6de8d422810f7fe3b0cd8c70844be57c0a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57823.go @@ -0,0 +1,76 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "runtime" + "unsafe" +) + +//go:noinline +func g(x *byte) *byte { return x } + +func main() { + slice() + str("AAAAAAAA", "BBBBBBBBB") +} + +func wait(done <-chan struct{}) bool { + for i := 0; i < 10; i++ { + runtime.GC() + select { + case <-done: + return true + default: + } + } + return false +} + +func slice() { + s := make([]byte, 100) + s[0] = 1 + one := unsafe.SliceData(s) + + done := make(chan struct{}) + runtime.SetFinalizer(one, func(*byte) { close(done) }) + + h := g(one) + + if wait(done) { + panic("GC'd early") + } + + if *h != 1 { + panic("lost one") + } + + if !wait(done) { + panic("never GC'd") + } +} + +var strDone = make(chan struct{}) + +//go:noinline +func str(x, y string) { + s := x + y // put in temporary on stack + p := unsafe.StringData(s) + runtime.SetFinalizer(p, func(*byte) { close(strDone) }) + + if wait(strDone) { + panic("GC'd early") + } + + if *p != 'A' { + panic("lost p") + } + + if !wait(strDone) { + panic("never GC'd") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57846.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57846.go new file mode 100644 index 0000000000000000000000000000000000000000..1aea97564e1a4f772a8db36d21720d0b450f3412 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57846.go @@ -0,0 +1,33 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func Float64D3(list [][][]float64, value float64) int { + valueCount := 0 + for _, listValue := range list { + valueCount += Float64D2(listValue, value) + } + return valueCount +} + +func Float64(list []float64, value float64) int { + valueCount := 0 + for _, listValue := range list { + if listValue == value { + valueCount++ + } + } + return valueCount +} + +func Float64D2(list [][]float64, value float64) int { + valueCount := 0 + for _, listValue := range list { + valueCount += Float64(listValue, value) + } + return valueCount +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5793.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5793.go new file mode 100644 index 0000000000000000000000000000000000000000..81041551c8841bcd211c77a3eb7661cb12f15d47 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5793.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5793: calling 2-arg builtin with multiple-result f() call expression gives +// spurious error. + +package main + +func complexArgs() (float64, float64) { + return 5, 7 +} + +func appendArgs() ([]string, string) { + return []string{"foo"}, "bar" +} + +func appendMultiArgs() ([]byte, byte, byte) { + return []byte{'a', 'b'}, '1', '2' +} + +func main() { + if c := complex(complexArgs()); c != 5+7i { + panic(c) + } + + if s := append(appendArgs()); len(s) != 2 || s[0] != "foo" || s[1] != "bar" { + panic(s) + } + + if b := append(appendMultiArgs()); len(b) != 4 || b[0] != 'a' || b[1] != 'b' || b[2] != '1' || b[3] != '2' { + panic(b) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue57955.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue57955.go new file mode 100644 index 0000000000000000000000000000000000000000..bee28c6e9962bd817f8ff5fbcae082175ea8e2b4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue57955.go @@ -0,0 +1,43 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 57955: ARM assembler fails to handle certain cases. + +package main + +func main() { + Decode[int16](nil) + Decode[uint16](nil) + Decode[float64](nil) +} + +func DecodeInt16(b []byte) (int16, int) { + return 0, 0 +} + +func DecodeUint16(b []byte) (uint16, int) { + return 0, 0 +} + +func DecodeFloat64(b []byte) (float64, int) { + return 0, 0 +} + +func Decode[T any](b []byte) (T, int) { + switch any(*new(T)).(type) { + case int16: + v, n := DecodeInt16(b) + return any(v).(T), n + case uint16: + v, n := DecodeUint16(b) + return any(v).(T), n + case float64: + v, n := DecodeFloat64(b) + return any(v).(T), n + default: + panic("") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5809.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5809.go new file mode 100644 index 0000000000000000000000000000000000000000..fc8eeef82fa03534b83aa99203feb866b6848ddc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5809.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5809: 6g and 8g attempted to constant propagate indexed LEA + +package main + +import "fmt" + +func main() { + const d16 = "0123456789ABCDEF" + k := 0x1234 + var x [4]byte + + x[0] = d16[k>>12&0xf] + x[1] = d16[k>>8&0xf] + x[2] = d16[k>>4&0xf] + x[3] = d16[k&0xf] + + if x != [4]byte{'1','2','3','4'} { + fmt.Println(x) + panic("x != [4]byte{'1','2','3','4'}") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58161.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58161.go new file mode 100644 index 0000000000000000000000000000000000000000..33113f65637d11e8e0a1c9dc1e4f125ae52e80c7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58161.go @@ -0,0 +1,15 @@ +// compile -d=ssa/check/seed=1 + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func F[G int]() int { + return len(make([]int, copy([]G{}, []G{}))) +} + +func main() { + F[int]() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5820.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5820.go new file mode 100644 index 0000000000000000000000000000000000000000..1046d66afbed17adfb8ebe36e553b069de13adee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5820.go @@ -0,0 +1,18 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 5820: register clobber when clearfat and 64 bit arithmetic is interleaved. + +package main + +func main() { + array := make([][]int, 2) + index := uint64(1) + array[index] = nil + if array[1] != nil { + panic("array[1] != nil") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58293.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58293.go new file mode 100644 index 0000000000000000000000000000000000000000..58d550025341a63c058c727e2e1ffe3248e5155a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58293.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var bar = f(13579) + +func f(x uint16) uint16 { + return x>>8 | x<<8 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.go new file mode 100644 index 0000000000000000000000000000000000000000..fff3d211f33bffa15e30bc451d7379c17986dd9a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "reflect" + "runtime" +) + +func f(n int) int { + return n % 2 +} + +func g(n int) int { + return f(n) +} + +func name(fn any) (res string) { + return runtime.FuncForPC(uintptr(reflect.ValueOf(fn).Pointer())).Name() +} + +func main() { + println(name(f)) + println(name(g)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.out new file mode 100644 index 0000000000000000000000000000000000000000..f347287480f374140164e684754334cd9eb505a1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300.out @@ -0,0 +1,2 @@ +main.f +main.g diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.go new file mode 100644 index 0000000000000000000000000000000000000000..5192b3f0f42e084491bbfb8045b37e40106537dd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "reflect" + "runtime" +) + +type T struct { + a, b int +} + +func f(t *T) int { + if t != nil { + return t.b + } + return 0 +} + +func g(t *T) int { + return f(t) + 5 +} + +func main() { + x(f) + x(g) +} +func x(v any) { + println(runtime.FuncForPC(reflect.ValueOf(v).Pointer()).Name()) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.out new file mode 100644 index 0000000000000000000000000000000000000000..f347287480f374140164e684754334cd9eb505a1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58300b.out @@ -0,0 +1,2 @@ +main.f +main.g diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58325.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58325.go new file mode 100644 index 0000000000000000000000000000000000000000..d37089c800f710a7c1aa2a8eace1ea48c045aa03 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58325.go @@ -0,0 +1,23 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type S1 struct { + s2 S2 +} + +type S2 struct{} + +func (S2) Make() S2 { + return S2{} +} + +func (S1) Make() S1 { + return S1{s2: S2{}.Make()} +} + +var _ = S1{}.Make() diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58339.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58339.go new file mode 100644 index 0000000000000000000000000000000000000000..5c4c5c0a8fb9072a250cb3bfa8a9718e7d06f921 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58339.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58341.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58341.go new file mode 100644 index 0000000000000000000000000000000000000000..c7b09bee9fb78568bb275408f0de4fd68105f9e6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58341.go @@ -0,0 +1,30 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type S[T comparable] struct { + m map[T]T +} + +func (s S[T]) M1(node T) { + defer delete(s.m, node) +} + +func (s S[T]) M2(node T) { + defer func() { + delete(s.m, node) + }() +} + +func (s S[T]) M3(node T) { + defer f(s.m, node) +} + +//go:noinline +func f[T comparable](map[T]T, T) {} + +var _ = S[int]{} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58345.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58345.go new file mode 100644 index 0000000000000000000000000000000000000000..ede8ffd1ecb13578f421c98b26dc1394460de8f0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58345.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type I1 interface { + int | any +} + +type I2 interface { + int | any +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5841.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5841.go new file mode 100644 index 0000000000000000000000000000000000000000..2be1aeefb14661c214be7276939dcad276ef3ab1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5841.go @@ -0,0 +1,16 @@ +// build + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5841: 8g produces invalid CMPL $0, $0. +// Similar to issue 5002, used to fail at link time. + +package main + +func main() { + var y int + if y%1 == 0 { + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58439.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58439.go new file mode 100644 index 0000000000000000000000000000000000000000..ad3650f6be9ecc69cd847b2616660567bcf4e405 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58439.go @@ -0,0 +1,14 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var x = f(-1) +var y = f(64) + +func f(x int) int { + return 1 << x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5856.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5856.go new file mode 100644 index 0000000000000000000000000000000000000000..f13258854e5c45e72de8bf1447271e576545e662 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5856.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "runtime" + "strings" +) + +func main() { + f() + panic("deferred function not run") +} + +var x = 1 + +func f() { + if x == 0 { + return + } + defer g() + panic("panic") +} + +func g() { + _, file, line, _ := runtime.Caller(2) + if !strings.HasSuffix(file, "issue5856.go") || line != 28 { + fmt.Printf("BUG: defer called from %s:%d, want issue5856.go:28\n", file, line) + os.Exit(1) + } + os.Exit(0) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58563.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58563.go new file mode 100644 index 0000000000000000000000000000000000000000..5c4c5c0a8fb9072a250cb3bfa8a9718e7d06f921 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58563.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58572.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58572.go new file mode 100644 index 0000000000000000000000000000000000000000..7461d593af555ffedb611502c3b2d1f77be93df9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58572.go @@ -0,0 +1,29 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func New() resource { + return &Client{} +} + +type resource interface { + table() +} + +type Client struct { + m map[Key1]int +} + +func (c *Client) table() {} + +type Key1 struct { + K Key2 +} + +type Key2 struct { + f [2]any +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58671.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58671.go new file mode 100644 index 0000000000000000000000000000000000000000..ae8f7a3ad6c9b3148985db780d11a841a2ee089a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58671.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func g[P any](...P) P { var zero P; return zero } + +var ( + _ int = g(1, 2) + _ rune = g(1, 'a') + _ float64 = g(1, 'a', 2.3) + _ float64 = g('a', 2.3) + _ complex128 = g(2.3, 'a', 1i) +) + +func main() {} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue58826.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue58826.go new file mode 100644 index 0000000000000000000000000000000000000000..de92002ed744cbcc966b642d8b85a7a02a038a96 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue58826.go @@ -0,0 +1,23 @@ +// compile -dynlink + +//go:build 386 || amd64 || arm || arm64 || ppc64le || s390x +// (platforms that support -dynlink flag) + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 58826: assembler cannot handle global access with large +// offset in -dynlink mode on ARM64. + +package p + +var x [2197]uint8 + +func F() { + for _, i := range x { + G(i) + } +} + +func G(uint8) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5910.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5910.go new file mode 100644 index 0000000000000000000000000000000000000000..54e74bac8dd0217c979976c37d5e99c622e397da --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5910.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 5910: parsing of unnamed struct types +// in inlined bodies was broken. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59169.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59169.go new file mode 100644 index 0000000000000000000000000000000000000000..61e2a95d107186f873a45522ad1e0cb792ff4e78 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59169.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 59169: caused gofrontend crash. + +package p + +func F(p *[]byte) { + *(*[1]byte)(*p) = *(*[1]byte)((*p)[1:]) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59174.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59174.go new file mode 100644 index 0000000000000000000000000000000000000000..33a19a46532952b7b4be2fdb54dacbe53dc7006c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59174.go @@ -0,0 +1,12 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func p() { + s := make([]int, copy([]byte{' '}, "")-1) + _ = append([]int{}, make([]int, len(s))...) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59190.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59190.go new file mode 100644 index 0000000000000000000000000000000000000000..48273eaaa2861957b960e3cc1dc79442886a7a20 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59190.go @@ -0,0 +1,39 @@ +// errorcheck + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +type E [1 << 30]complex128 + +var a [1 << 30]E +var _ = unsafe.Sizeof(a) // ERROR "too large" + +var s struct { + _ [1 << 30]E + x int +} +var _ = unsafe.Offsetof(s.x) // ERROR "too large" + +// Test case from issue (modified so it also triggers on 32-bit platforms). + +type A [1]int +type S struct { + x A + y [1 << 30]A + z [1 << 30]struct{} +} +type T [1 << 30][1 << 30]S + +func _() { + var a A + var s S + var t T + _ = unsafe.Sizeof(a) + _ = unsafe.Sizeof(s) + _ = unsafe.Sizeof(t) // ERROR "too large" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59293.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59293.go new file mode 100644 index 0000000000000000000000000000000000000000..1f05fe9a7ac1aa2416c56c2b6fc5f233dbb6581d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59293.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "unsafe" + +//go:noinline +func f(x []byte) bool { + return unsafe.SliceData(x) != nil +} + +//go:noinline +func g(x string) bool { + return unsafe.StringData(x) != nil +} + +func main() { + if f(nil) { + panic("bad f") + } + if g("") { + panic("bad g") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59334.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59334.go new file mode 100644 index 0000000000000000000000000000000000000000..06c12cf92ffe6ff8c33444cd101c2d4a96dbb58b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59334.go @@ -0,0 +1,18 @@ +// run -tags=purego -gcflags=all=-d=checkptr + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "crypto/subtle" + +func main() { + dst := make([]byte, 5) + src := make([]byte, 5) + for _, n := range []int{1024, 2048} { // just to make the size non-constant + b := make([]byte, n) + subtle.XORBytes(dst, src, b[n-5:]) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59338.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59338.go new file mode 100644 index 0000000000000000000000000000000000000000..8ba3fd2b3b911dadb87d5375e060bbfb7c487645 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59338.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Smoke test for reverse type inference. +// The type checker has more expansive tests. + +package main + +func main() { + var f1 func(int) int + f1 = g1 + if f1(1) != g1(1) { + panic(1) + } + + var f2 func(int) string = g2 + if f2(2) != "" { + panic(2) + } + + if g3(g1, 3) != g1(3) { + panic(3) + } + + if g4(g2, 4) != "" { + panic(4) + } +} + +func g1[P any](x P) P { return x } +func g2[P, Q any](x P) Q { var q Q; return q } + +func g3(f1 func(int) int, x int) int { return f1(x) } +func g4(f2 func(int) string, x int) string { return f2(x) } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59367.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59367.go new file mode 100644 index 0000000000000000000000000000000000000000..32a79e120841ccba0804c0c81f55baf89c836c62 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59367.go @@ -0,0 +1,80 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var b [8]byte + one := uint8(1) + f16(&one, b[:2]) + if b[1] != 1 { + println("2-byte value lost") + } + f32(&one, b[:4]) + if b[3] != 1 { + println("4-byte value lost") + } + f64(&one, b[:8]) + if b[7] != 1 { + println("8-byte value lost") + } +} + +//go:noinline +func f16(p *uint8, b []byte) { + _ = b[1] // bounds check + x := *p // load a byte + y := uint16(x) // zero extend to 16 bits + b[0] = byte(y >> 8) // compute ROLW + b[1] = byte(y) + nop() // spill/restore ROLW + b[0] = byte(y >> 8) // use ROLW + b[1] = byte(y) +} + +//go:noinline +func f32(p *uint8, b []byte) { + _ = b[3] // bounds check + x := *p // load a byte + y := uint32(x) // zero extend to 32 bits + b[0] = byte(y >> 24) // compute ROLL + b[1] = byte(y >> 16) + b[2] = byte(y >> 8) + b[3] = byte(y) + nop() // spill/restore ROLL + b[0] = byte(y >> 24) // use ROLL + b[1] = byte(y >> 16) + b[2] = byte(y >> 8) + b[3] = byte(y) +} + +//go:noinline +func f64(p *uint8, b []byte) { + _ = b[7] // bounds check + x := *p // load a byte + y := uint64(x) // zero extend to 64 bits + b[0] = byte(y >> 56) // compute ROLQ + b[1] = byte(y >> 48) + b[2] = byte(y >> 40) + b[3] = byte(y >> 32) + b[4] = byte(y >> 24) + b[5] = byte(y >> 16) + b[6] = byte(y >> 8) + b[7] = byte(y) + nop() // spill/restore ROLQ + b[0] = byte(y >> 56) // use ROLQ + b[1] = byte(y >> 48) + b[2] = byte(y >> 40) + b[3] = byte(y >> 32) + b[4] = byte(y >> 24) + b[5] = byte(y >> 16) + b[6] = byte(y >> 8) + b[7] = byte(y) +} + +//go:noinline +func nop() { +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59378.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59378.go new file mode 100644 index 0000000000000000000000000000000000000000..8ff198eaa7bec38936ffa75e0cfcdd9275de465e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59378.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f() { + F([]int{}, func(*int) bool { return true }) +} + +func F[S []E, E any](a S, fn func(*E) bool) { + for _, v := range a { + G(a, func(e E) bool { return fn(&v) }) + } +} + +func G[E any](s []E, f func(E) bool) int { + for i, v := range s { + if f(v) { + return i + } + } + return -1 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59404.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59404.go new file mode 100644 index 0000000000000000000000000000000000000000..0f391e6af1acfec07446a3032691a0e31615b465 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59404.go @@ -0,0 +1,61 @@ +// build -gcflags=-l=4 + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Interface interface { + MonitoredResource() (resType string, labels map[string]string) + Done() +} + +func Autodetect() Interface { + return func() Interface { + Do(func() { + var ad, gd Interface + + go func() { + defer gd.Done() + ad = aad() + }() + go func() { + defer ad.Done() + gd = aad() + defer func() { recover() }() + }() + + autoDetected = ad + if gd != nil { + autoDetected = gd + } + }) + return autoDetected + }() +} + +var autoDetected Interface +var G int + +type If int + +func (x If) MonitoredResource() (resType string, labels map[string]string) { + return "", nil +} + +//go:noinline +func (x If) Done() { + G++ +} + +//go:noinline +func Do(fn func()) { + fn() +} + +//go:noinline +func aad() Interface { + var x If + return x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59404part2.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59404part2.go new file mode 100644 index 0000000000000000000000000000000000000000..37fa029a1d53c7decd8a1e8e8a079dc682537e16 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59404part2.go @@ -0,0 +1,24 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var G func(int) int + +//go:noinline +func callclo(q, r int) int { + p := func(z int) int { + G = func(int) int { return 1 } + return z + 1 + } + res := p(q) ^ p(r) // These calls to "p" will be inlined + G = p + return res +} + +func main() { + callclo(1, 2) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59411.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59411.go new file mode 100644 index 0000000000000000000000000000000000000000..fc35c9801d2d9bd1c5fc831b52d6b3d5bcddb469 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59411.go @@ -0,0 +1,77 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "math" + "reflect" +) + +func main() { + for i := 0; i < 100; i++ { + f() + g() + } +} + +func f() { + // Allocate map. + m := map[float64]int{} + // Fill to just before a growth trigger. + const N = 13 << 4 // 6.5 * 2 * 2^k + for i := 0; i < N; i++ { + m[math.NaN()] = i + } + // Trigger growth. + m[math.NaN()] = N + + // Iterate through map. + i := 0 + for range m { + if i == 6 { + // Partway through iteration, clear the map. + clear(m) + } else if i > 6 { + // If we advance to the next iteration, that's a bug. + panic("BAD") + } + i++ + } + if len(m) != 0 { + panic("clear did not empty the map") + } +} + +func g() { + // Allocate map. + m := map[float64]int{} + // Fill to just before a growth trigger. + const N = 13 << 4 // 6.5 * 2 * 2^k + for i := 0; i < N; i++ { + m[math.NaN()] = i + } + // Trigger growth. + m[math.NaN()] = N + + // Iterate through map. + i := 0 + v := reflect.ValueOf(m) + iter := v.MapRange() + for iter.Next() { + if i == 6 { + // Partway through iteration, clear the map. + v.Clear() + } else if i > 6 { + // If we advance to the next iteration, that's a bug. + panic("BAD") + } + i++ + } + if v.Len() != 0 { + panic("clear did not empty the map") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5957.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5957.go new file mode 100644 index 0000000000000000000000000000000000000000..891d8e6d2eefff3631ccbfa8a354893cd5a63804 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5957.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.go new file mode 100644 index 0000000000000000000000000000000000000000..a16817aec0a2a7ee47f068359e30808747d14253 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func foo() { + println("foo") +} + +func main() { + fn := foo + for _, fn = range list { + fn() + } +} + +var list = []func(){ + func() { + println("1") + }, + func() { + println("2") + }, + func() { + println("3") + }, +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.out new file mode 100644 index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59572.out @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue5963.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue5963.go new file mode 100644 index 0000000000000000000000000000000000000000..f828303e492674f9e21e4a0676e09d0f69e0eb61 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue5963.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Used to die in runtime due to init goroutine exiting while +// locked to main thread. + +package main + +import ( + "os" + "runtime" +) + +func init() { + c := make(chan int, 1) + defer func() { + c <- 0 + }() + go func() { + os.Exit(<-c) + }() + runtime.Goexit() +} + +func main() { +} + +/* Before fix: + +invalid m->locked = 2 +fatal error: internal lockOSThread error + +goroutine 2 [runnable]: +runtime.MHeap_Scavenger() + /Users/rsc/g/go/src/pkg/runtime/mheap.c:438 +runtime.goexit() + /Users/rsc/g/go/src/pkg/runtime/proc.c:1313 +created by runtime.main + /Users/rsc/g/go/src/pkg/runtime/proc.c:165 + +goroutine 3 [runnable]: +main.func·002() + /Users/rsc/g/go/test/fixedbugs/issue5963.go:22 +created by main.init·1 + /Users/rsc/g/go/test/fixedbugs/issue5963.go:24 +0xb9 +exit status 2 +*/ diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59638.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59638.go new file mode 100644 index 0000000000000000000000000000000000000000..bba6265322c0e2ec0e599afe31a7de49f9de0b62 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59638.go @@ -0,0 +1,65 @@ +// build -gcflags=-l=4 + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Interface interface { + MonitoredResource() (resType string, labels map[string]string) + Done() +} + +func Autodetect(x int) Interface { + return func() Interface { + func() Interface { + x++ + Do(func() { + var ad, gd Interface + + go func() { + defer gd.Done() + ad = aad() + }() + go func() { + defer ad.Done() + gd = aad() + defer func() { recover() }() + }() + + autoDetected = ad + if gd != nil { + autoDetected = gd + } + }) + return autoDetected + }() + return nil + }() +} + +var autoDetected Interface +var G int + +type If int + +func (x If) MonitoredResource() (resType string, labels map[string]string) { + return "", nil +} + +//go:noinline +func (x If) Done() { + G++ +} + +//go:noinline +func Do(fn func()) { + fn() +} + +//go:noinline +func aad() Interface { + var x If + return x +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59680.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59680.go new file mode 100644 index 0000000000000000000000000000000000000000..d21f61fa32a52e429c263d6842a922ef0fb90be4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59680.go @@ -0,0 +1,100 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "sync" + "time" +) + +type B struct { + pid int + f func() (uint64, error) + wg sync.WaitGroup + v uint64 +} + +func newB(pid int) *B { + return &B{ + pid: pid, + } +} + +//go:noinline +func Sq(i int) uint64 { + S++ + return uint64(i * i) +} + +type RO func(*B) + +var ROSL = []RO{ + Bad(), +} + +func Bad() RO { + return func(b *B) { + b.f = func() (uint64, error) { + return Sq(b.pid), nil + } + } +} + +func (b *B) startit() chan<- struct{} { + stop := make(chan struct{}) + b.wg.Add(1) + go func() { + defer b.wg.Done() + var v uint64 + for { + select { + case <-stop: + b.v = v + return + case <-time.After(1 * time.Millisecond): + r, err := b.f() + if err != nil { + panic("bad") + } + v = r + } + } + }() + return stop +} + +var S, G int + +//go:noinline +func rec(x int) int { + if x == 0 { + return 9 + } + return rec(x-1) + 1 +} + +//go:noinline +func recur(x int) { + for i := 0; i < x; i++ { + G = rec(i) + } +} + +func main() { + b := newB(17) + for _, opt := range ROSL { + opt(b) + } + stop := b.startit() + + // see if we can get some stack growth/moving + recur(10101) + + if stop != nil { + stop <- struct{}{} + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue59709.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue59709.go new file mode 100644 index 0000000000000000000000000000000000000000..8fe8d8783fbc8efbcc76d7bb88b3fec5068e2896 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue59709.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6004.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6004.go new file mode 100644 index 0000000000000000000000000000000000000000..99d6ab85ea5def02b1e3cac9b95d92c59cdb6d3f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6004.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + _ = nil // ERROR "use of untyped nil" + _, _ = nil, 1 // ERROR "use of untyped nil" + _, _ = 1, nil // ERROR "use of untyped nil" + _ = append(nil, 1, 2, 3) // ERROR "untyped nil|nil" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6036.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6036.go new file mode 100644 index 0000000000000000000000000000000000000000..e7c2557864356c54fb1bb44acf8d2ca50136a7db --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6036.go @@ -0,0 +1,45 @@ +// compile + +//go:build !386 && !arm && !mips && !mipsle && !amd64p32 + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6036: 6g's backend generates OINDREG with +// offsets larger than 32-bit. + +package main + +type T struct { + Large [1 << 31]byte + A int + B int +} + +func F(t *T) { + t.B = t.A +} + +type T2 [1<<31 + 2]byte + +func F2(t *T2) { + t[1<<31+1] = 42 +} + +type T3 [1<<15 + 1][1<<15 + 1]int + +func F3(t *T3) { + t[1<<15][1<<15] = 42 +} + +type S struct { + A int32 + B int32 +} + +type T4 [1<<29 + 1]S + +func F4(t *T4) { + t[1<<29].B = 42 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6055.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6055.go new file mode 100644 index 0000000000000000000000000000000000000000..459434892aa1c3508f9359eac984bb6210543af0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6055.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "runtime" + +type Closer interface { + Close() +} + +func nilInterfaceDeferCall() { + defer func() { + // make sure a traceback happens with jmpdefer on the stack + runtime.GC() + }() + var x Closer + defer x.Close() +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("did not panic") + } + }() + f() +} + +func main() { + shouldPanic(nilInterfaceDeferCall) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60582.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60582.go new file mode 100644 index 0000000000000000000000000000000000000000..f698918098fa59bc20c1f50f36c8ae3e050a65ee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60582.go @@ -0,0 +1,15 @@ +// build + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func main() { + a, b := 5, 7 + fmt.Println(min(a, b)) + fmt.Println(max(a, b)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60601.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60601.go new file mode 100644 index 0000000000000000000000000000000000000000..530898985721ebe0fc22191ff3ce1034678779cd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60601.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "strings" + "unsafe" +) + +func shift[T any]() int64 { + return 1 << unsafe.Sizeof(*new(T)) +} + +func div[T any]() uintptr { + return 1 / unsafe.Sizeof(*new(T)) +} + +func add[T any]() int64 { + return 1<<63 - 1 + int64(unsafe.Sizeof(*new(T))) +} + +func main() { + shift[[62]byte]() + shift[[63]byte]() + shift[[64]byte]() + shift[[100]byte]() + shift[[1e6]byte]() + + add[[1]byte]() + shouldPanic("divide by zero", func() { div[[0]byte]() }) +} + +func shouldPanic(str string, f func()) { + defer func() { + err := recover() + if err == nil { + panic("did not panic") + } + s := err.(error).Error() + if !strings.Contains(s, str) { + panic("got panic " + s + ", want " + str) + } + }() + + f() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60945.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60945.go new file mode 100644 index 0000000000000000000000000000000000000000..5c4c5c0a8fb9072a250cb3bfa8a9718e7d06f921 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60945.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60982.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60982.go new file mode 100644 index 0000000000000000000000000000000000000000..4e5fc34646f756dc16aafba8e2409385a4761e61 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60982.go @@ -0,0 +1,2023 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f(x int, b bool) int { + if x >= 1000 { + if b { // from #61041 + var a struct{ f int64 } + _ = max(0, a.f) + } + + return max(x, 2000) + } + // generate 1000 basic blocks to put this function + // well into the "large function" phi generation algorithm. + switch x { + case 0: + return 0 + case 1: + return 1 + case 2: + return 2 + case 3: + return 3 + case 4: + return 4 + case 5: + return 5 + case 6: + return 6 + case 7: + return 7 + case 8: + return 8 + case 9: + return 9 + case 10: + return 10 + case 11: + return 11 + case 12: + return 12 + case 13: + return 13 + case 14: + return 14 + case 15: + return 15 + case 16: + return 16 + case 17: + return 17 + case 18: + return 18 + case 19: + return 19 + case 20: + return 20 + case 21: + return 21 + case 22: + return 22 + case 23: + return 23 + case 24: + return 24 + case 25: + return 25 + case 26: + return 26 + case 27: + return 27 + case 28: + return 28 + case 29: + return 29 + case 30: + return 30 + case 31: + return 31 + case 32: + return 32 + case 33: + return 33 + case 34: + return 34 + case 35: + return 35 + case 36: + return 36 + case 37: + return 37 + case 38: + return 38 + case 39: + return 39 + case 40: + return 40 + case 41: + return 41 + case 42: + return 42 + case 43: + return 43 + case 44: + return 44 + case 45: + return 45 + case 46: + return 46 + case 47: + return 47 + case 48: + return 48 + case 49: + return 49 + case 50: + return 50 + case 51: + return 51 + case 52: + return 52 + case 53: + return 53 + case 54: + return 54 + case 55: + return 55 + case 56: + return 56 + case 57: + return 57 + case 58: + return 58 + case 59: + return 59 + case 60: + return 60 + case 61: + return 61 + case 62: + return 62 + case 63: + return 63 + case 64: + return 64 + case 65: + return 65 + case 66: + return 66 + case 67: + return 67 + case 68: + return 68 + case 69: + return 69 + case 70: + return 70 + case 71: + return 71 + case 72: + return 72 + case 73: + return 73 + case 74: + return 74 + case 75: + return 75 + case 76: + return 76 + case 77: + return 77 + case 78: + return 78 + case 79: + return 79 + case 80: + return 80 + case 81: + return 81 + case 82: + return 82 + case 83: + return 83 + case 84: + return 84 + case 85: + return 85 + case 86: + return 86 + case 87: + return 87 + case 88: + return 88 + case 89: + return 89 + case 90: + return 90 + case 91: + return 91 + case 92: + return 92 + case 93: + return 93 + case 94: + return 94 + case 95: + return 95 + case 96: + return 96 + case 97: + return 97 + case 98: + return 98 + case 99: + return 99 + case 100: + return 100 + case 101: + return 101 + case 102: + return 102 + case 103: + return 103 + case 104: + return 104 + case 105: + return 105 + case 106: + return 106 + case 107: + return 107 + case 108: + return 108 + case 109: + return 109 + case 110: + return 110 + case 111: + return 111 + case 112: + return 112 + case 113: + return 113 + case 114: + return 114 + case 115: + return 115 + case 116: + return 116 + case 117: + return 117 + case 118: + return 118 + case 119: + return 119 + case 120: + return 120 + case 121: + return 121 + case 122: + return 122 + case 123: + return 123 + case 124: + return 124 + case 125: + return 125 + case 126: + return 126 + case 127: + return 127 + case 128: + return 128 + case 129: + return 129 + case 130: + return 130 + case 131: + return 131 + case 132: + return 132 + case 133: + return 133 + case 134: + return 134 + case 135: + return 135 + case 136: + return 136 + case 137: + return 137 + case 138: + return 138 + case 139: + return 139 + case 140: + return 140 + case 141: + return 141 + case 142: + return 142 + case 143: + return 143 + case 144: + return 144 + case 145: + return 145 + case 146: + return 146 + case 147: + return 147 + case 148: + return 148 + case 149: + return 149 + case 150: + return 150 + case 151: + return 151 + case 152: + return 152 + case 153: + return 153 + case 154: + return 154 + case 155: + return 155 + case 156: + return 156 + case 157: + return 157 + case 158: + return 158 + case 159: + return 159 + case 160: + return 160 + case 161: + return 161 + case 162: + return 162 + case 163: + return 163 + case 164: + return 164 + case 165: + return 165 + case 166: + return 166 + case 167: + return 167 + case 168: + return 168 + case 169: + return 169 + case 170: + return 170 + case 171: + return 171 + case 172: + return 172 + case 173: + return 173 + case 174: + return 174 + case 175: + return 175 + case 176: + return 176 + case 177: + return 177 + case 178: + return 178 + case 179: + return 179 + case 180: + return 180 + case 181: + return 181 + case 182: + return 182 + case 183: + return 183 + case 184: + return 184 + case 185: + return 185 + case 186: + return 186 + case 187: + return 187 + case 188: + return 188 + case 189: + return 189 + case 190: + return 190 + case 191: + return 191 + case 192: + return 192 + case 193: + return 193 + case 194: + return 194 + case 195: + return 195 + case 196: + return 196 + case 197: + return 197 + case 198: + return 198 + case 199: + return 199 + case 200: + return 200 + case 201: + return 201 + case 202: + return 202 + case 203: + return 203 + case 204: + return 204 + case 205: + return 205 + case 206: + return 206 + case 207: + return 207 + case 208: + return 208 + case 209: + return 209 + case 210: + return 210 + case 211: + return 211 + case 212: + return 212 + case 213: + return 213 + case 214: + return 214 + case 215: + return 215 + case 216: + return 216 + case 217: + return 217 + case 218: + return 218 + case 219: + return 219 + case 220: + return 220 + case 221: + return 221 + case 222: + return 222 + case 223: + return 223 + case 224: + return 224 + case 225: + return 225 + case 226: + return 226 + case 227: + return 227 + case 228: + return 228 + case 229: + return 229 + case 230: + return 230 + case 231: + return 231 + case 232: + return 232 + case 233: + return 233 + case 234: + return 234 + case 235: + return 235 + case 236: + return 236 + case 237: + return 237 + case 238: + return 238 + case 239: + return 239 + case 240: + return 240 + case 241: + return 241 + case 242: + return 242 + case 243: + return 243 + case 244: + return 244 + case 245: + return 245 + case 246: + return 246 + case 247: + return 247 + case 248: + return 248 + case 249: + return 249 + case 250: + return 250 + case 251: + return 251 + case 252: + return 252 + case 253: + return 253 + case 254: + return 254 + case 255: + return 255 + case 256: + return 256 + case 257: + return 257 + case 258: + return 258 + case 259: + return 259 + case 260: + return 260 + case 261: + return 261 + case 262: + return 262 + case 263: + return 263 + case 264: + return 264 + case 265: + return 265 + case 266: + return 266 + case 267: + return 267 + case 268: + return 268 + case 269: + return 269 + case 270: + return 270 + case 271: + return 271 + case 272: + return 272 + case 273: + return 273 + case 274: + return 274 + case 275: + return 275 + case 276: + return 276 + case 277: + return 277 + case 278: + return 278 + case 279: + return 279 + case 280: + return 280 + case 281: + return 281 + case 282: + return 282 + case 283: + return 283 + case 284: + return 284 + case 285: + return 285 + case 286: + return 286 + case 287: + return 287 + case 288: + return 288 + case 289: + return 289 + case 290: + return 290 + case 291: + return 291 + case 292: + return 292 + case 293: + return 293 + case 294: + return 294 + case 295: + return 295 + case 296: + return 296 + case 297: + return 297 + case 298: + return 298 + case 299: + return 299 + case 300: + return 300 + case 301: + return 301 + case 302: + return 302 + case 303: + return 303 + case 304: + return 304 + case 305: + return 305 + case 306: + return 306 + case 307: + return 307 + case 308: + return 308 + case 309: + return 309 + case 310: + return 310 + case 311: + return 311 + case 312: + return 312 + case 313: + return 313 + case 314: + return 314 + case 315: + return 315 + case 316: + return 316 + case 317: + return 317 + case 318: + return 318 + case 319: + return 319 + case 320: + return 320 + case 321: + return 321 + case 322: + return 322 + case 323: + return 323 + case 324: + return 324 + case 325: + return 325 + case 326: + return 326 + case 327: + return 327 + case 328: + return 328 + case 329: + return 329 + case 330: + return 330 + case 331: + return 331 + case 332: + return 332 + case 333: + return 333 + case 334: + return 334 + case 335: + return 335 + case 336: + return 336 + case 337: + return 337 + case 338: + return 338 + case 339: + return 339 + case 340: + return 340 + case 341: + return 341 + case 342: + return 342 + case 343: + return 343 + case 344: + return 344 + case 345: + return 345 + case 346: + return 346 + case 347: + return 347 + case 348: + return 348 + case 349: + return 349 + case 350: + return 350 + case 351: + return 351 + case 352: + return 352 + case 353: + return 353 + case 354: + return 354 + case 355: + return 355 + case 356: + return 356 + case 357: + return 357 + case 358: + return 358 + case 359: + return 359 + case 360: + return 360 + case 361: + return 361 + case 362: + return 362 + case 363: + return 363 + case 364: + return 364 + case 365: + return 365 + case 366: + return 366 + case 367: + return 367 + case 368: + return 368 + case 369: + return 369 + case 370: + return 370 + case 371: + return 371 + case 372: + return 372 + case 373: + return 373 + case 374: + return 374 + case 375: + return 375 + case 376: + return 376 + case 377: + return 377 + case 378: + return 378 + case 379: + return 379 + case 380: + return 380 + case 381: + return 381 + case 382: + return 382 + case 383: + return 383 + case 384: + return 384 + case 385: + return 385 + case 386: + return 386 + case 387: + return 387 + case 388: + return 388 + case 389: + return 389 + case 390: + return 390 + case 391: + return 391 + case 392: + return 392 + case 393: + return 393 + case 394: + return 394 + case 395: + return 395 + case 396: + return 396 + case 397: + return 397 + case 398: + return 398 + case 399: + return 399 + case 400: + return 400 + case 401: + return 401 + case 402: + return 402 + case 403: + return 403 + case 404: + return 404 + case 405: + return 405 + case 406: + return 406 + case 407: + return 407 + case 408: + return 408 + case 409: + return 409 + case 410: + return 410 + case 411: + return 411 + case 412: + return 412 + case 413: + return 413 + case 414: + return 414 + case 415: + return 415 + case 416: + return 416 + case 417: + return 417 + case 418: + return 418 + case 419: + return 419 + case 420: + return 420 + case 421: + return 421 + case 422: + return 422 + case 423: + return 423 + case 424: + return 424 + case 425: + return 425 + case 426: + return 426 + case 427: + return 427 + case 428: + return 428 + case 429: + return 429 + case 430: + return 430 + case 431: + return 431 + case 432: + return 432 + case 433: + return 433 + case 434: + return 434 + case 435: + return 435 + case 436: + return 436 + case 437: + return 437 + case 438: + return 438 + case 439: + return 439 + case 440: + return 440 + case 441: + return 441 + case 442: + return 442 + case 443: + return 443 + case 444: + return 444 + case 445: + return 445 + case 446: + return 446 + case 447: + return 447 + case 448: + return 448 + case 449: + return 449 + case 450: + return 450 + case 451: + return 451 + case 452: + return 452 + case 453: + return 453 + case 454: + return 454 + case 455: + return 455 + case 456: + return 456 + case 457: + return 457 + case 458: + return 458 + case 459: + return 459 + case 460: + return 460 + case 461: + return 461 + case 462: + return 462 + case 463: + return 463 + case 464: + return 464 + case 465: + return 465 + case 466: + return 466 + case 467: + return 467 + case 468: + return 468 + case 469: + return 469 + case 470: + return 470 + case 471: + return 471 + case 472: + return 472 + case 473: + return 473 + case 474: + return 474 + case 475: + return 475 + case 476: + return 476 + case 477: + return 477 + case 478: + return 478 + case 479: + return 479 + case 480: + return 480 + case 481: + return 481 + case 482: + return 482 + case 483: + return 483 + case 484: + return 484 + case 485: + return 485 + case 486: + return 486 + case 487: + return 487 + case 488: + return 488 + case 489: + return 489 + case 490: + return 490 + case 491: + return 491 + case 492: + return 492 + case 493: + return 493 + case 494: + return 494 + case 495: + return 495 + case 496: + return 496 + case 497: + return 497 + case 498: + return 498 + case 499: + return 499 + case 500: + return 500 + case 501: + return 501 + case 502: + return 502 + case 503: + return 503 + case 504: + return 504 + case 505: + return 505 + case 506: + return 506 + case 507: + return 507 + case 508: + return 508 + case 509: + return 509 + case 510: + return 510 + case 511: + return 511 + case 512: + return 512 + case 513: + return 513 + case 514: + return 514 + case 515: + return 515 + case 516: + return 516 + case 517: + return 517 + case 518: + return 518 + case 519: + return 519 + case 520: + return 520 + case 521: + return 521 + case 522: + return 522 + case 523: + return 523 + case 524: + return 524 + case 525: + return 525 + case 526: + return 526 + case 527: + return 527 + case 528: + return 528 + case 529: + return 529 + case 530: + return 530 + case 531: + return 531 + case 532: + return 532 + case 533: + return 533 + case 534: + return 534 + case 535: + return 535 + case 536: + return 536 + case 537: + return 537 + case 538: + return 538 + case 539: + return 539 + case 540: + return 540 + case 541: + return 541 + case 542: + return 542 + case 543: + return 543 + case 544: + return 544 + case 545: + return 545 + case 546: + return 546 + case 547: + return 547 + case 548: + return 548 + case 549: + return 549 + case 550: + return 550 + case 551: + return 551 + case 552: + return 552 + case 553: + return 553 + case 554: + return 554 + case 555: + return 555 + case 556: + return 556 + case 557: + return 557 + case 558: + return 558 + case 559: + return 559 + case 560: + return 560 + case 561: + return 561 + case 562: + return 562 + case 563: + return 563 + case 564: + return 564 + case 565: + return 565 + case 566: + return 566 + case 567: + return 567 + case 568: + return 568 + case 569: + return 569 + case 570: + return 570 + case 571: + return 571 + case 572: + return 572 + case 573: + return 573 + case 574: + return 574 + case 575: + return 575 + case 576: + return 576 + case 577: + return 577 + case 578: + return 578 + case 579: + return 579 + case 580: + return 580 + case 581: + return 581 + case 582: + return 582 + case 583: + return 583 + case 584: + return 584 + case 585: + return 585 + case 586: + return 586 + case 587: + return 587 + case 588: + return 588 + case 589: + return 589 + case 590: + return 590 + case 591: + return 591 + case 592: + return 592 + case 593: + return 593 + case 594: + return 594 + case 595: + return 595 + case 596: + return 596 + case 597: + return 597 + case 598: + return 598 + case 599: + return 599 + case 600: + return 600 + case 601: + return 601 + case 602: + return 602 + case 603: + return 603 + case 604: + return 604 + case 605: + return 605 + case 606: + return 606 + case 607: + return 607 + case 608: + return 608 + case 609: + return 609 + case 610: + return 610 + case 611: + return 611 + case 612: + return 612 + case 613: + return 613 + case 614: + return 614 + case 615: + return 615 + case 616: + return 616 + case 617: + return 617 + case 618: + return 618 + case 619: + return 619 + case 620: + return 620 + case 621: + return 621 + case 622: + return 622 + case 623: + return 623 + case 624: + return 624 + case 625: + return 625 + case 626: + return 626 + case 627: + return 627 + case 628: + return 628 + case 629: + return 629 + case 630: + return 630 + case 631: + return 631 + case 632: + return 632 + case 633: + return 633 + case 634: + return 634 + case 635: + return 635 + case 636: + return 636 + case 637: + return 637 + case 638: + return 638 + case 639: + return 639 + case 640: + return 640 + case 641: + return 641 + case 642: + return 642 + case 643: + return 643 + case 644: + return 644 + case 645: + return 645 + case 646: + return 646 + case 647: + return 647 + case 648: + return 648 + case 649: + return 649 + case 650: + return 650 + case 651: + return 651 + case 652: + return 652 + case 653: + return 653 + case 654: + return 654 + case 655: + return 655 + case 656: + return 656 + case 657: + return 657 + case 658: + return 658 + case 659: + return 659 + case 660: + return 660 + case 661: + return 661 + case 662: + return 662 + case 663: + return 663 + case 664: + return 664 + case 665: + return 665 + case 666: + return 666 + case 667: + return 667 + case 668: + return 668 + case 669: + return 669 + case 670: + return 670 + case 671: + return 671 + case 672: + return 672 + case 673: + return 673 + case 674: + return 674 + case 675: + return 675 + case 676: + return 676 + case 677: + return 677 + case 678: + return 678 + case 679: + return 679 + case 680: + return 680 + case 681: + return 681 + case 682: + return 682 + case 683: + return 683 + case 684: + return 684 + case 685: + return 685 + case 686: + return 686 + case 687: + return 687 + case 688: + return 688 + case 689: + return 689 + case 690: + return 690 + case 691: + return 691 + case 692: + return 692 + case 693: + return 693 + case 694: + return 694 + case 695: + return 695 + case 696: + return 696 + case 697: + return 697 + case 698: + return 698 + case 699: + return 699 + case 700: + return 700 + case 701: + return 701 + case 702: + return 702 + case 703: + return 703 + case 704: + return 704 + case 705: + return 705 + case 706: + return 706 + case 707: + return 707 + case 708: + return 708 + case 709: + return 709 + case 710: + return 710 + case 711: + return 711 + case 712: + return 712 + case 713: + return 713 + case 714: + return 714 + case 715: + return 715 + case 716: + return 716 + case 717: + return 717 + case 718: + return 718 + case 719: + return 719 + case 720: + return 720 + case 721: + return 721 + case 722: + return 722 + case 723: + return 723 + case 724: + return 724 + case 725: + return 725 + case 726: + return 726 + case 727: + return 727 + case 728: + return 728 + case 729: + return 729 + case 730: + return 730 + case 731: + return 731 + case 732: + return 732 + case 733: + return 733 + case 734: + return 734 + case 735: + return 735 + case 736: + return 736 + case 737: + return 737 + case 738: + return 738 + case 739: + return 739 + case 740: + return 740 + case 741: + return 741 + case 742: + return 742 + case 743: + return 743 + case 744: + return 744 + case 745: + return 745 + case 746: + return 746 + case 747: + return 747 + case 748: + return 748 + case 749: + return 749 + case 750: + return 750 + case 751: + return 751 + case 752: + return 752 + case 753: + return 753 + case 754: + return 754 + case 755: + return 755 + case 756: + return 756 + case 757: + return 757 + case 758: + return 758 + case 759: + return 759 + case 760: + return 760 + case 761: + return 761 + case 762: + return 762 + case 763: + return 763 + case 764: + return 764 + case 765: + return 765 + case 766: + return 766 + case 767: + return 767 + case 768: + return 768 + case 769: + return 769 + case 770: + return 770 + case 771: + return 771 + case 772: + return 772 + case 773: + return 773 + case 774: + return 774 + case 775: + return 775 + case 776: + return 776 + case 777: + return 777 + case 778: + return 778 + case 779: + return 779 + case 780: + return 780 + case 781: + return 781 + case 782: + return 782 + case 783: + return 783 + case 784: + return 784 + case 785: + return 785 + case 786: + return 786 + case 787: + return 787 + case 788: + return 788 + case 789: + return 789 + case 790: + return 790 + case 791: + return 791 + case 792: + return 792 + case 793: + return 793 + case 794: + return 794 + case 795: + return 795 + case 796: + return 796 + case 797: + return 797 + case 798: + return 798 + case 799: + return 799 + case 800: + return 800 + case 801: + return 801 + case 802: + return 802 + case 803: + return 803 + case 804: + return 804 + case 805: + return 805 + case 806: + return 806 + case 807: + return 807 + case 808: + return 808 + case 809: + return 809 + case 810: + return 810 + case 811: + return 811 + case 812: + return 812 + case 813: + return 813 + case 814: + return 814 + case 815: + return 815 + case 816: + return 816 + case 817: + return 817 + case 818: + return 818 + case 819: + return 819 + case 820: + return 820 + case 821: + return 821 + case 822: + return 822 + case 823: + return 823 + case 824: + return 824 + case 825: + return 825 + case 826: + return 826 + case 827: + return 827 + case 828: + return 828 + case 829: + return 829 + case 830: + return 830 + case 831: + return 831 + case 832: + return 832 + case 833: + return 833 + case 834: + return 834 + case 835: + return 835 + case 836: + return 836 + case 837: + return 837 + case 838: + return 838 + case 839: + return 839 + case 840: + return 840 + case 841: + return 841 + case 842: + return 842 + case 843: + return 843 + case 844: + return 844 + case 845: + return 845 + case 846: + return 846 + case 847: + return 847 + case 848: + return 848 + case 849: + return 849 + case 850: + return 850 + case 851: + return 851 + case 852: + return 852 + case 853: + return 853 + case 854: + return 854 + case 855: + return 855 + case 856: + return 856 + case 857: + return 857 + case 858: + return 858 + case 859: + return 859 + case 860: + return 860 + case 861: + return 861 + case 862: + return 862 + case 863: + return 863 + case 864: + return 864 + case 865: + return 865 + case 866: + return 866 + case 867: + return 867 + case 868: + return 868 + case 869: + return 869 + case 870: + return 870 + case 871: + return 871 + case 872: + return 872 + case 873: + return 873 + case 874: + return 874 + case 875: + return 875 + case 876: + return 876 + case 877: + return 877 + case 878: + return 878 + case 879: + return 879 + case 880: + return 880 + case 881: + return 881 + case 882: + return 882 + case 883: + return 883 + case 884: + return 884 + case 885: + return 885 + case 886: + return 886 + case 887: + return 887 + case 888: + return 888 + case 889: + return 889 + case 890: + return 890 + case 891: + return 891 + case 892: + return 892 + case 893: + return 893 + case 894: + return 894 + case 895: + return 895 + case 896: + return 896 + case 897: + return 897 + case 898: + return 898 + case 899: + return 899 + case 900: + return 900 + case 901: + return 901 + case 902: + return 902 + case 903: + return 903 + case 904: + return 904 + case 905: + return 905 + case 906: + return 906 + case 907: + return 907 + case 908: + return 908 + case 909: + return 909 + case 910: + return 910 + case 911: + return 911 + case 912: + return 912 + case 913: + return 913 + case 914: + return 914 + case 915: + return 915 + case 916: + return 916 + case 917: + return 917 + case 918: + return 918 + case 919: + return 919 + case 920: + return 920 + case 921: + return 921 + case 922: + return 922 + case 923: + return 923 + case 924: + return 924 + case 925: + return 925 + case 926: + return 926 + case 927: + return 927 + case 928: + return 928 + case 929: + return 929 + case 930: + return 930 + case 931: + return 931 + case 932: + return 932 + case 933: + return 933 + case 934: + return 934 + case 935: + return 935 + case 936: + return 936 + case 937: + return 937 + case 938: + return 938 + case 939: + return 939 + case 940: + return 940 + case 941: + return 941 + case 942: + return 942 + case 943: + return 943 + case 944: + return 944 + case 945: + return 945 + case 946: + return 946 + case 947: + return 947 + case 948: + return 948 + case 949: + return 949 + case 950: + return 950 + case 951: + return 951 + case 952: + return 952 + case 953: + return 953 + case 954: + return 954 + case 955: + return 955 + case 956: + return 956 + case 957: + return 957 + case 958: + return 958 + case 959: + return 959 + case 960: + return 960 + case 961: + return 961 + case 962: + return 962 + case 963: + return 963 + case 964: + return 964 + case 965: + return 965 + case 966: + return 966 + case 967: + return 967 + case 968: + return 968 + case 969: + return 969 + case 970: + return 970 + case 971: + return 971 + case 972: + return 972 + case 973: + return 973 + case 974: + return 974 + case 975: + return 975 + case 976: + return 976 + case 977: + return 977 + case 978: + return 978 + case 979: + return 979 + case 980: + return 980 + case 981: + return 981 + case 982: + return 982 + case 983: + return 983 + case 984: + return 984 + case 985: + return 985 + case 986: + return 986 + case 987: + return 987 + case 988: + return 988 + case 989: + return 989 + case 990: + return 990 + case 991: + return 991 + case 992: + return 992 + case 993: + return 993 + case 994: + return 994 + case 995: + return 995 + case 996: + return 996 + case 997: + return 997 + case 998: + return 998 + case 999: + return 999 + } + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60990.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60990.go new file mode 100644 index 0000000000000000000000000000000000000000..ce94fa719763fbe7778381075350f64256377ff6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60990.go @@ -0,0 +1,31 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T struct{ _, _ []int } + +func F[_ int]() { + var f0, f1 float64 + var b bool + _ = func(T, float64) bool { + b = deepEqual(0, 1) + return func() bool { + f1 = min(f0, 0) + return b + }() + }(T{nil, nil}, min(0, f1)) + f0 = min(0, 1) +} + +//go:noinline +func deepEqual(x, y any) bool { + return x == y +} + +func init() { + F[int]() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue60991.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue60991.go new file mode 100644 index 0000000000000000000000000000000000000000..e1d51e4300c56b36e0a81dff22b3d93d22ceba71 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue60991.go @@ -0,0 +1,13 @@ +// build + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "math" + +func f() { + _ = min(0.1, 0.2, math.Sqrt(1)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61127.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61127.go new file mode 100644 index 0000000000000000000000000000000000000000..c8ee5c5ee4f07666b9a291eae3e73ded3e338ae2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61127.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var V = []struct{}{} + +func main() { + clear(V) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61187.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61187.go new file mode 100644 index 0000000000000000000000000000000000000000..5e1762808df643a7f75f95381408c4cb51734315 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61187.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "reflect" + "unsafe" +) + +var slice = []byte{'H', 'e', 'l', 'l', 'o', ','} + +func main() { + ptr := uintptr(unsafe.Pointer(&slice)) + 100 + header := (*reflect.SliceHeader)(unsafe.Pointer(ptr)) + header.Data += 1 + fmt.Printf("%d %d\n", cap(slice), header.Cap) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6131.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6131.go new file mode 100644 index 0000000000000000000000000000000000000000..61548a2d52b2a7d13fa21062d7531557bb57365f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6131.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6131: missing typecheck after reducing +// n%1 == 0 to a constant value. + +package main + +func isGood(n int) bool { + return n%1 == 0 +} + +func main() { + if !isGood(256) { + panic("!isGood") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6140.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6140.go new file mode 100644 index 0000000000000000000000000000000000000000..dde7921d92f650e08983038173d53964d6d4a338 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6140.go @@ -0,0 +1,31 @@ +// compile + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6140: compiler incorrectly rejects method values +// whose receiver has an unnamed interface type. + +package p + +type T *interface { + m() int +} + +var x T + +var _ = (*x).m + +var y interface { + m() int +} + +var _ = y.m + +type I interface { + String() string +} + +var z *struct{ I } +var _ = z.String diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61778.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61778.go new file mode 100644 index 0000000000000000000000000000000000000000..5055c9e6a210b986f99f63c6d465216c43da8ca5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61778.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(s []byte) { + switch "" { + case string(append(s, 'a')): + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61895.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61895.go new file mode 100644 index 0000000000000000000000000000000000000000..cda649483df283ee30a6bad81218b8d4023d5be2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61895.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for { + } + + defer func() {}() + defer func() {}() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61908.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61908.go new file mode 100644 index 0000000000000000000000000000000000000000..f5d3bce678b09b5fba17aac926f8a166273fc7a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61908.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(p []byte) int { + switch "" < string(p) { + case true: + return 0 + default: + return 1 + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue61992.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue61992.go new file mode 100644 index 0000000000000000000000000000000000000000..d60605bb95d0a6ed433472c2be4e747d9f8c1221 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue61992.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 61992, inconsistent 'mem' juggling in expandCalls + +package p + +type S1 struct { + a, b, c []int + i int +} + +type S2 struct { + a, b []int + m map[int]int +} + +func F(i int, f func(S1, S2, int) int) int { + return f( + S1{}, + S2{m: map[int]int{}}, + 1<> right +} + +var n = uint16(65535) + +func main() { + println(f(n, boolInt32(int64(n^n) > 1))) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue64715.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue64715.out new file mode 100644 index 0000000000000000000000000000000000000000..7a53b35687b2b9f1c9ca5e29e30ddba92b3e9f66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue64715.out @@ -0,0 +1 @@ +65535 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue64826.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue64826.go new file mode 100644 index 0000000000000000000000000000000000000000..864c474a644e85d167abd28f0c1b378e4d3338f5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue64826.go @@ -0,0 +1,38 @@ +// build + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + f(g(false)) +} +func g(b bool) string { + if b { + return "z" + } + return "q" +} +func f(x string) int { + switch len(x) { + case 4: + return 4 + case 5: + return 5 + case 6: + return 6 + case 7: + return 7 + case 8: + return 8 + case 9: + return 9 + case 10: + return 10 + case 11: + return 11 + } + return 0 +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6500.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6500.go new file mode 100644 index 0000000000000000000000000000000000000000..b265f9ae39d3b98abe2cc5e3f40c408548893ac4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6500.go @@ -0,0 +1,29 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6500: missing error when fallthrough appears in a block. + +package main + +func main() { + var x int + switch x { + case 0: + { + fallthrough // ERROR "fallthrough" + } + case 1: + { + switch x { + case 2: + fallthrough + case 3: + } + } + fallthrough + default: + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6513.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6513.go new file mode 100644 index 0000000000000000000000000000000000000000..b32e0c5614d1060b1faa339c72d52c8ae30a9e69 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6513.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6513: embedded builtins may get incorrect qualified +// field name during import. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue65593.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue65593.go new file mode 100644 index 0000000000000000000000000000000000000000..892a78122ee4e73bff49e565481288abfd5d2cd7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue65593.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +const run = false + +func f() { + if !run { + return + } + + messages := make(chan struct{}, 1) +main: + for range messages { + break main + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6572.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6572.go new file mode 100644 index 0000000000000000000000000000000000000000..d69bf5aee2428ff3530b15fd4c7527da1df6c493 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6572.go @@ -0,0 +1,22 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func foo() (T, T) { // ERROR "undefined" + return 0, 0 +} + +func bar() (T, string, T) { // ERROR "undefined" + return 0, "", 0 +} + +func main() { + var x, y, z int + x, y = foo() + x, y, z = bar() // ERROR "cannot (use type|assign|use.*type) string|" + _, _, _ = x, y, z +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue65957.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue65957.go new file mode 100644 index 0000000000000000000000000000000000000000..48e4d34c9321298ea5007559d7008a0ec1071adf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue65957.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue66066.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue66066.go new file mode 100644 index 0000000000000000000000000000000000000000..a674503b4729b238063471cbad158736afa76fa1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue66066.go @@ -0,0 +1,41 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func main() { + testMod() + testMul() +} + +//go:noinline +func mod3(x uint32) uint64 { + return uint64(x % 3) +} + +func testMod() { + got := mod3(1<<32 - 1) + want := uint64((1<<32 - 1) % 3) + if got != want { + fmt.Printf("testMod: got %x want %x\n", got, want) + } + +} + +//go:noinline +func mul3(a uint32) uint64 { + return uint64(a * 3) +} + +func testMul() { + got := mul3(1<<32 - 1) + want := uint64((1<<32-1)*3 - 2<<32) + if got != want { + fmt.Printf("testMul: got %x want %x\n", got, want) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue66066b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue66066b.go new file mode 100644 index 0000000000000000000000000000000000000000..7540a85293a02e9e0ab0aac121777764060c90fa --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue66066b.go @@ -0,0 +1,58 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +//go:noinline +func f32(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x int32) uint64 { + return uint64(uint32(x)) +} + +//go:noinline +func f16(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x int16) uint64 { + return uint64(uint16(x)) +} + +//go:noinline +func f8(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x int8) uint64 { + return uint64(uint8(x)) +} + +//go:noinline +func g32(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x uint32) int64 { + return int64(int32(x)) +} + +//go:noinline +func g16(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x uint16) int64 { + return int64(int16(x)) +} + +//go:noinline +func g8(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, x uint8) int64 { + return int64(int8(x)) +} + +func main() { + if got := f32(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1); got != 0xffffffff { + println("bad f32", got) + } + if got := f16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1); got != 0xffff { + println("bad f16", got) + } + if got := f8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1); got != 0xff { + println("bad f8", got) + } + if got := g32(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xffffffff); got != -1 { + println("bad g32", got) + } + if got := g16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xffff); got != -1 { + println("bad g16", got) + } + if got := g8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff); got != -1 { + println("bad g8", got) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue66096.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue66096.go new file mode 100644 index 0000000000000000000000000000000000000000..f8621a18b4ec0b736012b51a376e584e14fa641b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue66096.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Message struct { + Header map[string][]string +} + +func f() { + m := Message{Header: map[string][]string{}} + m.Header[""] = append([]string(m.Header[""]), "") + _ = m +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.go new file mode 100644 index 0000000000000000000000000000000000000000..1ad6ca0b707ebc4bbdc7ec07777f18bf25faab8f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var ( + v0 = initv0() + v1 = initv1() +) + +const c = "c" + +func initv0() string { + println("initv0") + if c != "" { // have a dependency on c + return "" + } + return "" +} + +func initv1() string { + println("initv1") + return "" +} + +func main() { + // do nothing +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.out new file mode 100644 index 0000000000000000000000000000000000000000..36d1f17a68f30fceb6d783cb55a672485da8f4d4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue66575.out @@ -0,0 +1,2 @@ +initv0 +initv1 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6671.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6671.go new file mode 100644 index 0000000000000000000000000000000000000000..ce43f31d4f5e46e06595cdb31637e6da7165ec95 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6671.go @@ -0,0 +1,28 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6671: Logical operators should produce untyped bool for untyped operands. + +package p + +type mybool bool + +func _(x, y int) { + type mybool bool + var b mybool + _ = b + b = bool(true) // ERROR "cannot use" + b = true // permitted as expected + b = bool(true) && true // ERROR "cannot use" + b = true && true // permitted => && returns an untyped bool + b = x < y // permitted => x < y returns an untyped bool + b = true && x < y // permitted => result of && returns untyped bool + b = x < y && x < y // permitted => result of && returns untyped bool + b = x < y || x < y // permitted => result of || returns untyped bool + var c bool = true && x < y // permitted => result of && is bool + c = false || x < y // permitted => result of || returns untyped bool + _ = c +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703a.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703a.go new file mode 100644 index 0000000000000000000000000000000000000000..fe736f5bc6fdcf67ad4f88cacbe58bfcf7ddebbd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703a.go @@ -0,0 +1,16 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a function value. + +package funcvalue + +func fx() int { + _ = x + return 0 +} + +var x = fx // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703b.go new file mode 100644 index 0000000000000000000000000000000000000000..41510945c5a0358bf6bfca7437db557065573302 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703b.go @@ -0,0 +1,16 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a function call. + +package funccall + +func fx() int { + _ = x + return 0 +} + +var x = fx() // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703c.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703c.go new file mode 100644 index 0000000000000000000000000000000000000000..73d686c696ac1ce3aef22abdd2b0b652aa5c1287 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703c.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a method expression. + +package methexpr + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T.m // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703d.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703d.go new file mode 100644 index 0000000000000000000000000000000000000000..5d77c846cb4d0dd6bc2822befcccab589e787d44 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703d.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a method expression call. + +package methexprcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T.m(0) // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703e.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703e.go new file mode 100644 index 0000000000000000000000000000000000000000..604d4bfa5dd275cdba940d879fe76cc07854c11d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703e.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method value of a value literal. + +package litmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T(0).m // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703f.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703f.go new file mode 100644 index 0000000000000000000000000000000000000000..06c9cdff42d0c637532d75aec42bfd65f80f0cf1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703f.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method call of a value literal. + +package litmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T(0).m() // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703g.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703g.go new file mode 100644 index 0000000000000000000000000000000000000000..a2ca5a3e697f30adf1cb7c68e4a12eb8137b7d58 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703g.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in an embedded method expression. + +package embedmethexpr + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E.m // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703h.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703h.go new file mode 100644 index 0000000000000000000000000000000000000000..e26ce6a7e2b4cfb8535a9f13ab4d636c0ecbac7a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703h.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles when calling an embedded method expression. + +package embedmethexprcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E.m(E{0}) // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703i.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703i.go new file mode 100644 index 0000000000000000000000000000000000000000..af485b570d0f7fb04db6ba90a1c28465ad4c79ae --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703i.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in an embedded struct literal's method value. + +package embedlitmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E{}.m // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703j.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703j.go new file mode 100644 index 0000000000000000000000000000000000000000..0b72250f800664aa839d3521f9dfb5386ab0706e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703j.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in an embedded struct literal's method call. + +package embedlitmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E{}.m() // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703k.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703k.go new file mode 100644 index 0000000000000000000000000000000000000000..fad8edd1c8bce533f51afa876c1f955d71e5389e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703k.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a method value. + +package methvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var ( + t T + x = t.m // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703l.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703l.go new file mode 100644 index 0000000000000000000000000000000000000000..750c95e731ff8e8830c49036ca6346b86b771b0b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703l.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a method call. + +package methcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var ( + t T + x = t.m() // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703m.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703m.go new file mode 100644 index 0000000000000000000000000000000000000000..76469594060db719f19d6bb03a1be952ef9fcceb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703m.go @@ -0,0 +1,25 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method value of a value returned from a function call. + +package funcmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func f() T { + return T(0) +} + +var ( + t T + x = f().m // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703n.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703n.go new file mode 100644 index 0000000000000000000000000000000000000000..339789206bc485ef2e460b3255b939d4e652cc69 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703n.go @@ -0,0 +1,25 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method call of a value returned from a function call. + +package funcmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func f() T { + return T(0) +} + +var ( + t T + x = f().m() // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703o.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703o.go new file mode 100644 index 0000000000000000000000000000000000000000..87d706bbe8fbeefb90143c9d518e85620314db2b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703o.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in an embedded struct's method value. + +package embedmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var ( + e E + x = e.m // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703p.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703p.go new file mode 100644 index 0000000000000000000000000000000000000000..24ef94a72f4cc747fa5e6719288f82c546ab65c3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703p.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in an embedded struct's method call. + +package embedmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var ( + e E + x = e.m() // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703q.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703q.go new file mode 100644 index 0000000000000000000000000000000000000000..92bcab92fa04864aa3589cf9f6ce69b3d5d12d43 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703q.go @@ -0,0 +1,28 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method value of an embedded struct returned +// from a function call. + +package funcembedmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func g() E { + return E{0} +} + +type E struct{ T } + +var ( + e E + x = g().m // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703r.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703r.go new file mode 100644 index 0000000000000000000000000000000000000000..2b538ffa0475ca0634d30f423d55f8d248f107c9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703r.go @@ -0,0 +1,28 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method call of an embedded struct returned +// from a function call. + +package funcembedmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func g() E { + return E{0} +} + +type E struct{ T } + +var ( + e E + x = g().m() // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703s.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703s.go new file mode 100644 index 0000000000000000000000000000000000000000..74ab3866feb07ff8c84ecee894c96a30e946e79f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703s.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a pointer method expression. + +package ptrmethexpr + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T).pm // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703t.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703t.go new file mode 100644 index 0000000000000000000000000000000000000000..e9266b0c32c5a693626c481401c4f705ef7f5da2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703t.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the call of a pointer method expression. + +package ptrmethexprcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T).pm(nil) // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703u.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703u.go new file mode 100644 index 0000000000000000000000000000000000000000..9b03c17139f5a886781e75b00ce11312de43a588 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703u.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a pointer literal's method value. + +package ptrlitmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T)(nil).pm // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703v.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703v.go new file mode 100644 index 0000000000000000000000000000000000000000..349289cb90f50629611b255f7d119609c705ec01 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703v.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a pointer literal's method call. + +package ptrlitmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T)(nil).pm() // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703w.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703w.go new file mode 100644 index 0000000000000000000000000000000000000000..846b5f8c7df5856f0fc5b2c8622301f87f5da198 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703w.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a pointer value's method value. + +package ptrmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var ( + p *T + x = p.pm // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703x.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703x.go new file mode 100644 index 0000000000000000000000000000000000000000..828c09af21eee36d1c87ed784323c96a419c4db4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703x.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in a pointer value's method call. + +package ptrmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var ( + p *T + x = p.pm() // ERROR "initialization cycle|depends upon itself" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703y.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703y.go new file mode 100644 index 0000000000000000000000000000000000000000..01b8abd7aca9759d20e53e05cb59ac4a0875227c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703y.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method value of a pointer value returned +// from a function call. + +package funcptrmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +func pf() *T { + return nil +} + +var x = pf().pm // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6703z.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703z.go new file mode 100644 index 0000000000000000000000000000000000000000..76c17e2bb5a363318715e3f59762698b0b0c3d9b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6703z.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for cycles in the method call of a pointer value returned +// from a function call. + +package funcptrmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +func pf() *T { + return nil +} + +var x = pf().pm() // ERROR "initialization cycle|depends upon itself" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue67141.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue67141.go new file mode 100644 index 0000000000000000000000000000000000000000..0464d1f9e5e08713a25ce073fa95fe99d9a7b7ca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue67141.go @@ -0,0 +1,15 @@ +// errorcheck -lang=go1.22 + +//go:build go1.21 + +// We need a line directive before the package clause, +// but don't change file name or position so that the +// error message appears at the right place. + +//line issue67141.go:10 +package p + +func _() { + for range 10 { // ERROR "cannot range over 10" + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue67160.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue67160.go new file mode 100644 index 0000000000000000000000000000000000000000..be45a61420b7f384b6c551fea5ed25f59e6ceba9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue67160.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test to make sure that we don't try using larger loads for +// generated equality functions on architectures that can't do +// unaligned loads. + +package main + +// T has a big field that wants to be compared with larger loads/stores. +// T is "special" because of the unnamed field, so it needs a generated equality function. +// T is an odd number of bytes in size and has alignment 1. +type T struct { + src [8]byte + _ byte +} + +// U contains 8 copies of T, each at a different %8 alignment. +type U [8]T + +//go:noinline +func f(x, y *U) bool { + return *x == *y +} + +func main() { + var a U + _ = f(&a, &a) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue67255.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue67255.go new file mode 100644 index 0000000000000000000000000000000000000000..7ca7a239dd02cd3cf28df8324292bf31c048418e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue67255.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var zero int + +var sink any + +func main() { + var objs [][]*byte + for i := 10; i < 200; i++ { + // The objects we're allocating here are pointer-ful. Some will + // max out their size class, which are the ones we want. + // We also allocate from small to large, so that the object which + // maxes out its size class is the last one allocated in that class. + // This allocation pattern leaves the next object in the class + // unallocated, which we need to reproduce the bug. + objs = append(objs, make([]*byte, i)) + } + sink = objs // force heap allocation + + // Bug will happen as soon as the write barrier turns on. + for range 10000 { + sink = make([]*byte, 1024) + for _, s := range objs { + s = append(s, make([]*byte, zero)...) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6750.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6750.go new file mode 100644 index 0000000000000000000000000000000000000000..fca4e66aafe7615c0d52e4a42f861c4289e80ed1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6750.go @@ -0,0 +1,22 @@ +// errorcheck + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func printmany(nums ...int) { + for i, n := range nums { + fmt.Printf("%d: %d\n", i, n) + } + fmt.Printf("\n") +} + +func main() { + printmany(1, 2, 3) + printmany([]int{1, 2, 3}...) + printmany(1, "abc", []int{2, 3}...) // ERROR "too many arguments in call( to printmany\n\thave \(number, string, \.\.\.int\)\n\twant \(...int\))?" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6772.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6772.go new file mode 100644 index 0000000000000000000000000000000000000000..5cc89b47b537e7db05059d6b70d038d3c1972d58 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6772.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f1() { + for a, a := range []int{1, 2, 3} { // ERROR "a.* repeated on left side of :=|a redeclared" + println(a) + } +} + +func f2() { + var a int + for a, a := range []int{1, 2, 3} { // ERROR "a.* repeated on left side of :=|a redeclared" + println(a) + } + println(a) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6789.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6789.go new file mode 100644 index 0000000000000000000000000000000000000000..e3a2c3320ef1258f394b1f7f3bb9c2824027c8c4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6789.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6789: gccgo failed to find the hash function for an +// unexported struct embedded in an exported struct. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6847.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6847.go new file mode 100644 index 0000000000000000000000000000000000000000..da300bcd017f284ffd5b35b01e188360fcc88279 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6847.go @@ -0,0 +1,85 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6847: select clauses involving implicit conversion +// of channels trigger a spurious typechecking error during walk. + +package p + +type I1 interface { + String() +} +type I2 interface { + String() +} + +func F() { + var ( + cr <-chan int + cs chan<- int + c chan int + + ccr chan (<-chan int) + ccs chan chan<- int + cc chan chan int + + ok bool + ) + // Send cases. + select { + case ccr <- cr: + case ccr <- c: + } + select { + case ccs <- cs: + case ccs <- c: + } + select { + case ccr <- c: + default: + } + // Receive cases. + select { + case cr = <-cc: + case cs = <-cc: + case c = <-cc: + } + select { + case cr = <-cc: + default: + } + select { + case cr, ok = <-cc: + case cs, ok = <-cc: + case c = <-cc: + } + // Interfaces. + var ( + c1 chan I1 + c2 chan I2 + x1 I1 + x2 I2 + ) + select { + case c1 <- x1: + case c1 <- x2: + case c2 <- x1: + case c2 <- x2: + } + select { + case x1 = <-c1: + case x1 = <-c2: + case x2 = <-c1: + case x2 = <-c2: + } + select { + case x1, ok = <-c1: + case x1, ok = <-c2: + case x2, ok = <-c1: + case x2, ok = <-c2: + } + _ = ok +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6866.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6866.go new file mode 100644 index 0000000000000000000000000000000000000000..1080b276e7c7f389e52c0764d6cf7715edb2568e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6866.go @@ -0,0 +1,80 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// WARNING: GENERATED FILE - DO NOT MODIFY MANUALLY! +// (To generate, in go/types directory: go test -run=Hilbert -H=2 -out="h2.src") + +// This program tests arbitrary precision constant arithmetic +// by generating the constant elements of a Hilbert matrix H, +// its inverse I, and the product P = H*I. The product should +// be the identity matrix. +package main + +func main() { + if !ok { + print() + return + } +} + +// Hilbert matrix, n = 2 +const ( + h0_0, h0_1 = 1.0 / (iota + 1), 1.0 / (iota + 2) + h1_0, h1_1 +) + +// Inverse Hilbert matrix +const ( + i0_0 = +1 * b2_1 * b2_1 * b0_0 * b0_0 + i0_1 = -2 * b2_0 * b3_1 * b1_0 * b1_0 + + i1_0 = -2 * b3_1 * b2_0 * b1_1 * b1_1 + i1_1 = +3 * b3_0 * b3_0 * b2_1 * b2_1 +) + +// Product matrix +const ( + p0_0 = h0_0*i0_0 + h0_1*i1_0 + p0_1 = h0_0*i0_1 + h0_1*i1_1 + + p1_0 = h1_0*i0_0 + h1_1*i1_0 + p1_1 = h1_0*i0_1 + h1_1*i1_1 +) + +// Verify that product is identity matrix +const ok = p0_0 == 1 && p0_1 == 0 && + p1_0 == 0 && p1_1 == 1 && + true + +func print() { + println(p0_0, p0_1) + println(p1_0, p1_1) +} + +// Binomials +const ( + b0_0 = f0 / (f0 * f0) + + b1_0 = f1 / (f0 * f1) + b1_1 = f1 / (f1 * f0) + + b2_0 = f2 / (f0 * f2) + b2_1 = f2 / (f1 * f1) + b2_2 = f2 / (f2 * f0) + + b3_0 = f3 / (f0 * f3) + b3_1 = f3 / (f1 * f2) + b3_2 = f3 / (f2 * f1) + b3_3 = f3 / (f3 * f0) +) + +// Factorials +const ( + f0 = 1 + f1 = 1 + f2 = f1 * 2 + f3 = f2 * 3 +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6889.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6889.go new file mode 100644 index 0000000000000000000000000000000000000000..efd8b761483410ba3561c2a2ce44b635b9e66556 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6889.go @@ -0,0 +1,111 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6889: confusing error message: ovf in mpaddxx + +package main + +const ( + f1 = 1 + f2 = f1 * 2 + f3 = f2 * 3 + f4 = f3 * 4 + f5 = f4 * 5 + f6 = f5 * 6 + f7 = f6 * 7 + f8 = f7 * 8 + f9 = f8 * 9 + f10 = f9 * 10 + f11 = f10 * 11 + f12 = f11 * 12 + f13 = f12 * 13 + f14 = f13 * 14 + f15 = f14 * 15 + f16 = f15 * 16 + f17 = f16 * 17 + f18 = f17 * 18 + f19 = f18 * 19 + f20 = f19 * 20 + f21 = f20 * 21 + f22 = f21 * 22 + f23 = f22 * 23 + f24 = f23 * 24 + f25 = f24 * 25 + f26 = f25 * 26 + f27 = f26 * 27 + f28 = f27 * 28 + f29 = f28 * 29 + f30 = f29 * 30 + f31 = f30 * 31 + f32 = f31 * 32 + f33 = f32 * 33 + f34 = f33 * 34 + f35 = f34 * 35 + f36 = f35 * 36 + f37 = f36 * 37 + f38 = f37 * 38 + f39 = f38 * 39 + f40 = f39 * 40 + f41 = f40 * 41 + f42 = f41 * 42 + f43 = f42 * 43 + f44 = f43 * 44 + f45 = f44 * 45 + f46 = f45 * 46 + f47 = f46 * 47 + f48 = f47 * 48 + f49 = f48 * 49 + f50 = f49 * 50 + f51 = f50 * 51 + f52 = f51 * 52 + f53 = f52 * 53 + f54 = f53 * 54 + f55 = f54 * 55 + f56 = f55 * 56 + f57 = f56 * 57 + f58 = f57 * 58 + f59 = f58 * 59 + f60 = f59 * 60 + f61 = f60 * 61 + f62 = f61 * 62 + f63 = f62 * 63 + f64 = f63 * 64 + f65 = f64 * 65 + f66 = f65 * 66 + f67 = f66 * 67 + f68 = f67 * 68 + f69 = f68 * 69 + f70 = f69 * 70 + f71 = f70 * 71 + f72 = f71 * 72 + f73 = f72 * 73 + f74 = f73 * 74 + f75 = f74 * 75 + f76 = f75 * 76 + f77 = f76 * 77 + f78 = f77 * 78 + f79 = f78 * 79 + f80 = f79 * 80 + f81 = f80 * 81 + f82 = f81 * 82 + f83 = f82 * 83 + f84 = f83 * 84 + f85 = f84 * 85 + f86 = f85 * 86 + f87 = f86 * 87 + f88 = f87 * 88 + f89 = f88 * 89 + f90 = f89 * 90 + f91 = f90 * 91 + f92 = f91 * 92 + f93 = f92 * 93 + f94 = f93 * 94 + f95 = f94 * 95 + f96 = f95 * 96 + f97 = f96 * 97 + f98 = f97 * 98 + f99 = f98 * 99 // GC_ERROR "overflow" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.go new file mode 100644 index 0000000000000000000000000000000000000000..d7f8578029884d5e388d64427f49a02f9125602d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.go @@ -0,0 +1,13 @@ +// run + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "math" + +func main() { + println(math.Copysign(0, -1)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.out b/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.out new file mode 100644 index 0000000000000000000000000000000000000000..e2375f07766a6c0ee5a3ea8fecd849b481ec0ecb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6899.out @@ -0,0 +1 @@ +-0.000000e+000 diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6902.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6902.go new file mode 100644 index 0000000000000000000000000000000000000000..5c2c545d2ca3114adf79a9814a10e00088ae6ad9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6902.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 6902: confusing printing of large floating point constants + +package main + +import ( + "os" +) + +var x = -1e-10000 + +func main() { + if x != 0 { + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6964.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6964.go new file mode 100644 index 0000000000000000000000000000000000000000..36a3c5bb40f27245315ce700fe19af761b28b1d5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6964.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + _ = string(-4 + 2i + 2) // ERROR "-4 \+ 2i|invalid type conversion" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue6977.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue6977.go new file mode 100644 index 0000000000000000000000000000000000000000..4525e406b84fd348d811f1e9570b68e498453f61 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue6977.go @@ -0,0 +1,40 @@ +// errorcheck + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "io" + +// Alan's initial report. + +type I interface { f(); String() string } +type J interface { g(); String() string } + +type IJ1 = interface { I; J } +type IJ2 = interface { f(); g(); String() string } + +var _ = (*IJ1)(nil) == (*IJ2)(nil) // static assert that IJ1 and IJ2 are identical types + +// The canonical example. + +type ReadWriteCloser interface { io.ReadCloser; io.WriteCloser } + +// Some more cases. + +type M interface { m() } +type M32 interface { m() int32 } +type M64 interface { m() int64 } + +type U1 interface { m() } +type U2 interface { m(); M } +type U3 interface { M; m() } +type U4 interface { M; M; M } +type U5 interface { U1; U2; U3; U4 } + +type U6 interface { m(); m() } // ERROR "duplicate method .*m" +type U7 interface { M32; m() } // ERROR "duplicate method .*m" +type U8 interface { m(); M32 } // ERROR "duplicate method .*m" +type U9 interface { M32; M64 } // ERROR "duplicate method .*m" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7023.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7023.go new file mode 100644 index 0000000000000000000000000000000000000000..f18c6113ef1a618ba85e1faa5c5ba0c0ce3e187c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7023.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7023: corrupted export data when an inlined function +// contains a goto. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7044.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7044.go new file mode 100644 index 0000000000000000000000000000000000000000..00c78c8cb93913c471eea87ac2d4a3a3bbf23773 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7044.go @@ -0,0 +1,43 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7044: bad AMOVFD and AMOVDF assembly generation on +// arm for registers above 7. + +package main + +import ( + "fmt" + "reflect" +) + +func f() [16]float32 { + f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15 := + float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1) + // Use all 16 registers to do float32 --> float64 conversion. + d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15 := + float64(f0), float64(f1), float64(f2), float64(f3), float64(f4), float64(f5), float64(f6), float64(f7), float64(f8), float64(f9), float64(f10), float64(f11), float64(f12), float64(f13), float64(f14), float64(f15) + // Use all 16 registers to do float64 --> float32 conversion. + g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15 := + float32(d0), float32(d1), float32(d2), float32(d3), float32(d4), float32(d5), float32(d6), float32(d7), float32(d8), float32(d9), float32(d10), float32(d11), float32(d12), float32(d13), float32(d14), float32(d15) + // Force another conversion, so that the previous conversion doesn't + // get optimized away into constructing the returned array. With current + // optimizations, constructing the returned array uses only + // a single register. + e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15 := + float64(g0), float64(g1), float64(g2), float64(g3), float64(g4), float64(g5), float64(g6), float64(g7), float64(g8), float64(g9), float64(g10), float64(g11), float64(g12), float64(g13), float64(g14), float64(g15) + return [16]float32{ + float32(e0), float32(e1), float32(e2), float32(e3), float32(e4), float32(e5), float32(e6), float32(e7), float32(e8), float32(e9), float32(e10), float32(e11), float32(e12), float32(e13), float32(e14), float32(e15), + } +} + +func main() { + want := [16]float32{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} + got := f() + if !reflect.DeepEqual(got, want) { + fmt.Printf("f() = %#v; want %#v\n", got, want) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7050.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7050.go new file mode 100644 index 0000000000000000000000000000000000000000..be7a118f57516fa8f4821a32d0f93ac720fbbf1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7050.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" +) + +func main() { + _, err := os.Stdout.Write(nil) + if err != nil { + fmt.Printf("BUG: os.Stdout.Write(nil) = %v\n", err) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7083.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7083.go new file mode 100644 index 0000000000000000000000000000000000000000..79bfd3b5ef9b2ccc0c5aaac070fe44426d3d8821 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7083.go @@ -0,0 +1,22 @@ +// run + +package main + +import "runtime/debug" + +func f(m map[int]*string, i int) { + s := "" + m[i] = &s +} + +func main() { + debug.SetGCPercent(0) + m := map[int]*string{} + for i := 0; i < 40; i++ { + f(m, i) + if len(*m[i]) != 0 { + println("bad length", i, m[i], len(*m[i])) + panic("bad length") + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7129.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7129.go new file mode 100644 index 0000000000000000000000000000000000000000..70dc26303e188d9dbbb976adb8b481bd897f5a0f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7129.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7129: inconsistent "wrong arg type" error for multivalued g in f(g()) + +package main + +func f(int) {} + +func g() bool { return true } + +func h(int, int) {} + +func main() { + f(g()) // ERROR "in argument to f|incompatible type|cannot convert" + f(true) // ERROR "in argument to f|incompatible type|cannot convert" + h(true, true) // ERROR "in argument to h|incompatible type|cannot convert" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7150.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7150.go new file mode 100644 index 0000000000000000000000000000000000000000..52eed93756f7c36c37004e7931842bb61bde213e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7150.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 7150: array index out of bounds error off by one + +package main + +func main() { + _ = [0]int{-1: 50} // ERROR "index must be non-negative integer constant|index expression is negative|must not be negative" + _ = [0]int{0: 0} // ERROR "index 0 out of bounds \[0:0\]|out of range" + _ = [0]int{5: 25} // ERROR "index 5 out of bounds \[0:0\]|out of range" + _ = [10]int{2: 10, 15: 30} // ERROR "index 15 out of bounds \[0:10\]|out of range" + _ = [10]int{5: 5, 1: 1, 12: 12} // ERROR "index 12 out of bounds \[0:10\]|out of range" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7153.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7153.go new file mode 100644 index 0000000000000000000000000000000000000000..0b29ec779b3cc98a322cbee64e0b96680e320c86 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7153.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7153: array invalid index error duplicated on successive bad values + +package p + +var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type untyped bool\) as type int in slice literal|undefined name .*a|incompatible type|cannot use" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7214.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7214.go new file mode 100644 index 0000000000000000000000000000000000000000..82ddf74c31c526f7da73adb0132dd0ab2a03a959 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7214.go @@ -0,0 +1,30 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7214: No duplicate key error for maps with interface{} key type + +package p + +var _ = map[interface{}]int{2: 1, 2: 1} // ERROR "duplicate key" +var _ = map[interface{}]int{int(2): 1, int16(2): 1} +var _ = map[interface{}]int{int16(2): 1, int16(2): 1} // ERROR "duplicate key" + +type S string + +var _ = map[interface{}]int{"a": 1, "a": 1} // ERROR "duplicate key" +var _ = map[interface{}]int{"a": 1, S("a"): 1} +var _ = map[interface{}]int{S("a"): 1, S("a"): 1} // ERROR "duplicate key" + +type I interface { + f() +} + +type N int + +func (N) f() {} + +var _ = map[I]int{N(0): 1, N(2): 1} +var _ = map[I]int{N(2): 1, N(2): 1} // ERROR "duplicate key" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7223.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7223.go new file mode 100644 index 0000000000000000000000000000000000000000..129e20f49702279738e87c9ac716a28484e6599b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7223.go @@ -0,0 +1,21 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var bits1 uint = 10 + +const bits2 uint = 10 + +func main() { + _ = make([]byte, 1<> 1) + a := make([]struct{}, length) + b := make([]struct{}, length) + _ = append(a, b...) +} + +func main() { + shouldPanic(f) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7590.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7590.go new file mode 100644 index 0000000000000000000000000000000000000000..607a3ae606d12de507b05704f643c1e982f6b54a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7590.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7590: gccgo incorrectly traverses nested composite literals. + +package p + +type S struct { + F int +} + +var M = map[string]S{ + "a": { F: 1 }, +} + +var P = M["a"] + +var F = P.F diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7648.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7648.go new file mode 100644 index 0000000000000000000000000000000000000000..b391c4a3177c4e0e442c13d04259b5bbe2fad1dd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7648.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7648: spurious "bad negated constant" for complex constants. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7675.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7675.go new file mode 100644 index 0000000000000000000000000000000000000000..6cda05f332fc8986c93b00c6fdf32250beb0d780 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7675.go @@ -0,0 +1,24 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7675: fewer errors for wrong argument count + +package p + +func f(string, int, float64, string) + +func g(string, int, float64, ...string) + +func main() { + f(1, 0.5, "hello") // ERROR "not enough arguments|incompatible type" + f("1", 2, 3.1, "4") + f(1, 0.5, "hello", 4, 5) // ERROR "too many arguments|incompatible type" + g(1, 0.5) // ERROR "not enough arguments|incompatible type" + g("1", 2, 3.1) + g(1, 0.5, []int{3, 4}...) // ERROR "not enough arguments|incompatible type" + g("1", 2, 3.1, "4", "5") + g(1, 0.5, "hello", 4, []int{5, 6}...) // ERROR "too many arguments|truncated to integer" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7690.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7690.go new file mode 100644 index 0000000000000000000000000000000000000000..fea2aa16107a83c9136b0c91c31b385b227daa25 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7690.go @@ -0,0 +1,49 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 7690 - Stack and other routines did not back up initial PC +// into CALL instruction, instead reporting line number of next instruction, +// which might be on a different line. + +package main + +import ( + "bytes" + "regexp" + "runtime" + "strconv" +) + +func main() { + buf1 := make([]byte, 1000) + buf2 := make([]byte, 1000) + + runtime.Stack(buf1, false) // CALL is last instruction on this line + n := runtime.Stack(buf2, false) // CALL is followed by load of result from stack + + buf1 = buf1[:bytes.IndexByte(buf1, 0)] + buf2 = buf2[:n] + + re := regexp.MustCompile(`(?m)^main\.main\(\)\n.*/issue7690.go:([0-9]+)`) + m1 := re.FindStringSubmatch(string(buf1)) + if m1 == nil { + println("BUG: cannot find main.main in first trace") + return + } + m2 := re.FindStringSubmatch(string(buf2)) + if m2 == nil { + println("BUG: cannot find main.main in second trace") + return + } + + n1, _ := strconv.Atoi(m1[1]) + n2, _ := strconv.Atoi(m2[1]) + if n1+1 != n2 { + println("BUG: expect runtime.Stack on back to back lines, have", n1, n2) + println(string(buf1)) + println(string(buf2)) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7740.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7740.go new file mode 100644 index 0000000000000000000000000000000000000000..6bc6249d7e0b6bfc597bade2f4d506d63814e5a1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7740.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This test computes the precision of the compiler's internal multiprecision floats. + +package main + +import ( + "fmt" + "math" + "runtime" +) + +const ulp = (1.0 + (2.0 / 3.0)) - (5.0 / 3.0) + +func main() { + // adjust precision depending on compiler + var prec float64 + switch runtime.Compiler { + case "gc": + prec = math.Inf(1) // exact precision using rational arithmetic + case "gccgo": + prec = 256 + default: + // unknown compiler + return + } + p := 1 - math.Log(math.Abs(ulp))/math.Log(2) + if math.Abs(p-prec) > 1e-10 { + fmt.Printf("BUG: got %g; want %g\n", p, prec) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7742.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7742.go new file mode 100644 index 0000000000000000000000000000000000000000..dc167c22e834f66e7e43865f3c3f764ce3542118 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7742.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7742: cannot use &autotmp_0001 (type *map[string]string) as type *string in function argument + +package main + +var ( + m map[string]string + v string +) + +func main() { + m[v], _ = v, v +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7746.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7746.go new file mode 100644 index 0000000000000000000000000000000000000000..745496293d719cdfdeb6a8f88676f98c4c607b66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7746.go @@ -0,0 +1,133 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +const ( + c0 = 1 << 100 + c1 = c0 * c0 + c2 = c1 * c1 + c3 = c2 * c2 // GC_ERROR "overflow" + c4 = c3 * c3 + c5 = c4 * c4 + c6 = c5 * c5 + c7 = c6 * c6 + c8 = c7 * c7 + c9 = c8 * c8 + c10 = c9 * c9 + c11 = c10 * c10 + c12 = c11 * c11 + c13 = c12 * c12 + c14 = c13 * c13 // GCCGO_ERROR "overflow" + c15 = c14 * c14 + c16 = c15 * c15 + c17 = c16 * c16 + c18 = c17 * c17 + c19 = c18 * c18 + c20 = c19 * c19 + c21 = c20 * c20 + c22 = c21 * c21 + c23 = c22 * c22 + c24 = c23 * c23 + c25 = c24 * c24 + c26 = c25 * c25 + c27 = c26 * c26 + c28 = c27 * c27 + c29 = c28 * c28 + c30 = c29 * c29 + c31 = c30 * c30 + c32 = c31 * c31 + c33 = c32 * c32 + c34 = c33 * c33 + c35 = c34 * c34 + c36 = c35 * c35 + c37 = c36 * c36 + c38 = c37 * c37 + c39 = c38 * c38 + c40 = c39 * c39 + c41 = c40 * c40 + c42 = c41 * c41 + c43 = c42 * c42 + c44 = c43 * c43 + c45 = c44 * c44 + c46 = c45 * c45 + c47 = c46 * c46 + c48 = c47 * c47 + c49 = c48 * c48 + c50 = c49 * c49 + c51 = c50 * c50 + c52 = c51 * c51 + c53 = c52 * c52 + c54 = c53 * c53 + c55 = c54 * c54 + c56 = c55 * c55 + c57 = c56 * c56 + c58 = c57 * c57 + c59 = c58 * c58 + c60 = c59 * c59 + c61 = c60 * c60 + c62 = c61 * c61 + c63 = c62 * c62 + c64 = c63 * c63 + c65 = c64 * c64 + c66 = c65 * c65 + c67 = c66 * c66 + c68 = c67 * c67 + c69 = c68 * c68 + c70 = c69 * c69 + c71 = c70 * c70 + c72 = c71 * c71 + c73 = c72 * c72 + c74 = c73 * c73 + c75 = c74 * c74 + c76 = c75 * c75 + c77 = c76 * c76 + c78 = c77 * c77 + c79 = c78 * c78 + c80 = c79 * c79 + c81 = c80 * c80 + c82 = c81 * c81 + c83 = c82 * c82 + c84 = c83 * c83 + c85 = c84 * c84 + c86 = c85 * c85 + c87 = c86 * c86 + c88 = c87 * c87 + c89 = c88 * c88 + c90 = c89 * c89 + c91 = c90 * c90 + c92 = c91 * c91 + c93 = c92 * c92 + c94 = c93 * c93 + c95 = c94 * c94 + c96 = c95 * c95 + c97 = c96 * c96 + c98 = c97 * c97 + c99 = c98 * c98 + c100 = c99 * c99 +) + +func main() { + println(c1 / c1) + println(c2 / c2) + println(c3 / c3) + println(c4 / c4) + println(c5 / c5) + println(c6 / c6) + println(c7 / c7) + println(c8 / c8) + println(c9 / c9) + println(c10 / c10) + println(c20 / c20) + println(c30 / c30) + println(c40 / c40) + println(c50 / c50) + println(c60 / c60) + println(c70 / c70) + println(c80 / c80) + println(c90 / c90) + println(c100 / c100) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7760.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7760.go new file mode 100644 index 0000000000000000000000000000000000000000..7e1d03596eb9808fd1e32265f717ffeae3386b37 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7760.go @@ -0,0 +1,25 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify that pointers can't be used as constants. + +package main + +import "unsafe" + +type myPointer unsafe.Pointer + +const _ = unsafe.Pointer(uintptr(1)) // ERROR "is not (a )?constant|invalid constant type" +const _ = myPointer(uintptr(1)) // ERROR "is not (a )?constant|invalid constant type" + +const _ = (*int)(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant|invalid constant type" +const _ = (*int)(myPointer(uintptr(1))) // ERROR "is not (a )?constant|invalid constant type" + +const _ = uintptr(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant|expression is not constant" +const _ = uintptr(myPointer(uintptr(1))) // ERROR "is not (a )?constant|expression is no constant" + +const _ = []byte("") // ERROR "is not (a )?constant|invalid constant type" +const _ = []rune("") // ERROR "is not (a )?constant|invalid constant type" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7794.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7794.go new file mode 100644 index 0000000000000000000000000000000000000000..f31de94079e502ecb428d2f8c4d8866d6a24b884 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7794.go @@ -0,0 +1,12 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var a [10]int + const ca = len(a) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7863.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7863.go new file mode 100644 index 0000000000000000000000000000000000000000..da2ed05ba00f41d368c9b728670ba8e4172237af --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7863.go @@ -0,0 +1,60 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Foo int64 + +func (f *Foo) F() int64 { + return int64(*f) +} + +type Bar int64 + +func (b Bar) F() int64 { + return int64(b) +} + +type Baz int32 + +func (b Baz) F() int64 { + return int64(b) +} + +func main() { + foo := Foo(123) + f := foo.F + if foo.F() != f() { + bug() + fmt.Println("foo.F", foo.F(), f()) + } + bar := Bar(123) + f = bar.F + if bar.F() != f() { + bug() + fmt.Println("bar.F", bar.F(), f()) // duh! + } + + baz := Baz(123) + f = baz.F + if baz.F() != f() { + bug() + fmt.Println("baz.F", baz.F(), f()) + } +} + +var bugged bool + +func bug() { + if !bugged { + bugged = true + fmt.Println("BUG") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7867.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7867.go new file mode 100644 index 0000000000000000000000000000000000000000..166506e721cc7bfff5f15fc9f493e311a24e834d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7867.go @@ -0,0 +1,43 @@ +// runoutput + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7867. + +package main + +import "fmt" + +const tpl = ` +func Test%d(t %s) { + _ = t + _ = t +} +` + +func main() { + fmt.Println("package main") + types := []string{ + // These types always passed + "bool", "int", "rune", + "*int", "uintptr", + "float32", "float64", + "chan struct{}", + "map[string]struct{}", + "func()", "func(string)error", + + // These types caused compilation failures + "complex64", "complex128", + "struct{}", "struct{n int}", "struct{e error}", "struct{m map[string]string}", + "string", + "[4]byte", + "[]byte", + "interface{}", "error", + } + for i, typ := range types { + fmt.Printf(tpl, i, typ) + } + fmt.Println("func main() {}") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7884.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7884.go new file mode 100644 index 0000000000000000000000000000000000000000..ab7a858e54658bce323a1a712b6e9f11b886f004 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7884.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func main() { + var ii interface{} = 5 + zz, err := ii.(interface{}) + fmt.Println(zz, err) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7921.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7921.go new file mode 100644 index 0000000000000000000000000000000000000000..0f09951c9687d93b201896f795064c4aaf4cd925 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7921.go @@ -0,0 +1,58 @@ +// errorcheck -0 -m + +//go:build !gcflags_noopt && !goexperiment.newinliner + +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo + +import "bytes" + +// In order to get desired results, we need a combination of +// both escape analysis and inlining. + +func bufferNotEscape() string { + // b itself does not escape, only its buf field will be + // copied during String() call, but object "handle" itself + // can be stack-allocated. + var b bytes.Buffer + b.WriteString("123") + b.Write([]byte{'4'}) // ERROR "\[\]byte{...} does not escape$" + return b.String() // ERROR "inlining call to bytes.\(\*Buffer\).String$" "string\(bytes.b.buf\[bytes.b.off:\]\) escapes to heap$" +} + +func bufferNoEscape2(xs []string) int { // ERROR "xs does not escape$" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" + for _, x := range xs { + b.WriteString(x) + } + return b.Len() // ERROR "inlining call to bytes.\(\*Buffer\).Len$" +} + +func bufferNoEscape3(xs []string) string { // ERROR "xs does not escape$" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" + for _, x := range xs { + b.WriteString(x) + b.WriteByte(',') + } + return b.String() // ERROR "inlining call to bytes.\(\*Buffer\).String$" "string\(bytes.b.buf\[bytes.b.off:\]\) escapes to heap$" +} + +func bufferNoEscape4() []byte { + var b bytes.Buffer + b.Grow(64) // ERROR "bufferNoEscape4 ignoring self-assignment in bytes.b.buf = bytes.b.buf\[:bytes.m\]$" "inlining call to bytes.\(\*Buffer\).Grow$" `".+" escapes to heap` + useBuffer(&b) + return b.Bytes() // ERROR "inlining call to bytes.\(\*Buffer\).Bytes$" +} + +func bufferNoEscape5() { // ERROR "can inline bufferNoEscape5$" + b := bytes.NewBuffer(make([]byte, 0, 128)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 128\) does not escape$" "inlining call to bytes.NewBuffer$" + useBuffer(b) +} + +//go:noinline +func useBuffer(b *bytes.Buffer) { // ERROR "b does not escape$" + b.WriteString("1234") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7944.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7944.go new file mode 100644 index 0000000000000000000000000000000000000000..960065b623bab841c0ed2ca55be563a83d60f667 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7944.go @@ -0,0 +1,40 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7944: +// Liveness bitmaps said b was live at call to g, +// but no one told the register optimizer. + +package main + +import "runtime" + +func f(b []byte) { + for len(b) > 0 { + n := len(b) + n = f1(n) + f2(b[n:]) + b = b[n:] + } + g() +} + +func f1(n int) int { + runtime.GC() + return n +} + +func f2(b []byte) { + runtime.GC() +} + +func g() { + runtime.GC() +} + +func main() { + f(make([]byte, 100)) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7995.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7995.go new file mode 100644 index 0000000000000000000000000000000000000000..af77a6d164d2bf96d54868b572345574e8c4e970 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7995.go @@ -0,0 +1,25 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7995: globals not flushed quickly enough. + +package main + +import "fmt" + +var ( + p = 1 + q = &p +) + +func main() { + p = 50 + *q = 100 + s := fmt.Sprintln(p, *q) + if s != "100 100\n" { + println("BUG:", s) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7995b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7995b.go new file mode 100644 index 0000000000000000000000000000000000000000..2f57371e379d3c77a246d8bbf477616b5666e743 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7995b.go @@ -0,0 +1,9 @@ +// rundir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 7995: globals not flushed quickly enough. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7996.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7996.go new file mode 100644 index 0000000000000000000000000000000000000000..1ee6fc709c47458c4dabc2c984ae81b9def45970 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7996.go @@ -0,0 +1,14 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// /tmp/x.go:5: illegal constant expression: bool == interface {} + +package p + +var m = map[interface{}]struct{}{ + nil: {}, + true: {}, +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7997.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7997.go new file mode 100644 index 0000000000000000000000000000000000000000..a342189a1f6dc3752214b561a0964ce5d0d20d27 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7997.go @@ -0,0 +1,53 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// /tmp/x.go:3: internal error: f &p (type *int) recorded as live on entry + +package p + +func f(ch chan int) *int { + select { + case p1x := <-ch: + return &p1x + default: + // ok + } + select { + case p1 := <-ch: + return &p1 + default: + // ok + } + select { + case p2 := <-ch: + return &p2 + case p3 := <-ch: + return &p3 + default: + // ok + } + select { + case p4, ok := <-ch: + if ok { + return &p4 + } + default: + // ok + } + select { + case p5, ok := <-ch: + if ok { + return &p5 + } + case p6, ok := <-ch: + if !ok { + return &p6 + } + default: + // ok + } + return nil +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue7998.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue7998.go new file mode 100644 index 0000000000000000000000000000000000000000..8da39e86f26979204a067598eb97930c654879fd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue7998.go @@ -0,0 +1,23 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// /tmp/x.go:5: cannot use _ as value + +package p + +func f(ch chan int) bool { + select { + case _, ok := <-ch: + return ok + } + _, ok := <-ch + _ = ok + select { + case _, _ = <-ch: + return true + } + return false +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8004.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8004.go new file mode 100644 index 0000000000000000000000000000000000000000..548ee1c72bdd648b78a1b3342877c7fa526acee6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8004.go @@ -0,0 +1,59 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "reflect" + "runtime" + "unsafe" +) + +func main() { + test1() + test2() +} + +func test1() { + var all []interface{} + for i := 0; i < 100; i++ { + p := new([]int) + *p = append(*p, 1, 2, 3, 4) + h := (*reflect.SliceHeader)(unsafe.Pointer(p)) + all = append(all, h, p) + } + runtime.GC() + for i := 0; i < 100; i++ { + p := *all[2*i+1].(*[]int) + if p[0] != 1 || p[1] != 2 || p[2] != 3 || p[3] != 4 { + println("BUG test1: bad slice at index", i, p[0], p[1], p[2], p[3]) + return + } + } +} + +type T struct { + H *reflect.SliceHeader + P *[]int +} + +func test2() { + var all []T + for i := 0; i < 100; i++ { + p := new([]int) + *p = append(*p, 1, 2, 3, 4) + h := (*reflect.SliceHeader)(unsafe.Pointer(p)) + all = append(all, T{H: h}, T{P: p}) + } + runtime.GC() + for i := 0; i < 100; i++ { + p := *all[2*i+1].P + if p[0] != 1 || p[1] != 2 || p[2] != 3 || p[3] != 4 { + println("BUG test2: bad slice at index", i, p[0], p[1], p[2], p[3]) + return + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8011.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8011.go new file mode 100644 index 0000000000000000000000000000000000000000..57af2a9b1f6c60b8cebcabbfaba2ff2292266293 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8011.go @@ -0,0 +1,18 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + c := make(chan chan int, 1) + c1 := make(chan int, 1) + c1 <- 42 + c <- c1 + x := <-<-c + if x != 42 { + println("BUG:", x, "!= 42") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8017.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8017.go new file mode 100644 index 0000000000000000000000000000000000000000..9afcdf0046b87a09c366b1258a832921ef5e07c0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8017.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issues 8017 and 8058: walk modifies nodes generated +// by slicelit and causes an internal error afterwards +// when gen_as_init parses it back. + +package main + +func F() { + var ch chan int + select { + case <-ch: + case <-make(chan int, len([2][]int{([][]int{})[len(ch)], []int{}})): + } +} + +func G() { + select { + case <-([1][]chan int{[]chan int{}})[0][0]: + default: + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8028.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8028.go new file mode 100644 index 0000000000000000000000000000000000000000..9f2649a5e32ffaf72362a42cf5690fcba1188a43 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8028.go @@ -0,0 +1,27 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8028. Used to fail in -race mode with "non-orig name" error. + +package p + +var ( + t2 = T{F, "s1"} + t1 = T{F, "s2"} + + tt = [...]T{t1, t2} +) + +type I interface{} + +type T struct { + F func() I + S string +} + +type E struct{} + +func F() I { return new(E) } diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8036.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8036.go new file mode 100644 index 0000000000000000000000000000000000000000..82ba7f7dafedfd4bb07e13a94e65bc819c046634 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8036.go @@ -0,0 +1,45 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8036. Stores necessary for stack scan being eliminated as redundant by optimizer. + +package main + +import "runtime" + +type T struct { + X *int + Y *int + Z *int +} + +type TI [3]uintptr + +//go:noinline +func G() (t TI) { + t[0] = 1 + t[1] = 2 + t[2] = 3 + return +} + +//go:noinline +func F() (t T) { + t.X = newint() + t.Y = t.X + t.Z = t.Y + return +} + +func newint() *int { + runtime.GC() + return nil +} + +func main() { + G() // leave non-pointers where F's return values go + F() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8039.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8039.go new file mode 100644 index 0000000000000000000000000000000000000000..ee00c60d3e56fe2731b50c89f074b1edd65a2c64 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8039.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8039. defer copy(x, <-c) did not rewrite <-c properly. + +package main + +func f(s []int) { + c := make(chan []int, 1) + c <- []int{1} + defer copy(s, <-c) +} + +func main() { + x := make([]int, 1) + f(x) + if x[0] != 1 { + println("BUG", x[0]) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8042.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8042.go new file mode 100644 index 0000000000000000000000000000000000000000..be15ef06cd2fd03554cf19292277d2af5f9559eb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8042.go @@ -0,0 +1,66 @@ +// compile + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify that gotos across non-variable declarations +// are accepted. + +package p + +func f1() { + goto L1 + const x = 0 +L1: + goto L2 + type T int +L2: +} + +func f2() { + { + goto L1 + } + const x = 0 +L1: + { + goto L2 + } + type T int +L2: +} + +func f3(d int) { + if d > 0 { + goto L1 + } else { + goto L2 + } + const x = 0 +L1: + switch d { + case 1: + goto L3 + case 2: + default: + goto L4 + } + type T1 int +L2: + const y = 1 +L3: + for d > 0 { + if d < 10 { + goto L4 + } + } + type T2 int +L4: + select { + default: + goto L5 + } + type T3 int +L5: +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8047.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8047.go new file mode 100644 index 0000000000000000000000000000000000000000..5ac4a0ef925dd2ebd3bf54d27097be54b330006b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8047.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8047. Stack copier shouldn't crash if there +// is a nil defer. + +package main + +func stackit(n int) { + if n == 0 { + return + } + stackit(n - 1) +} + +func main() { + defer func() { + // catch & ignore panic from nil defer below + err := recover() + if err == nil { + panic("defer of nil func didn't panic") + } + }() + defer ((func())(nil))() + stackit(1000) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8047b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8047b.go new file mode 100644 index 0000000000000000000000000000000000000000..5eaf9c5bacc8b1f8675080d64a6d1706a2830fd4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8047b.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8047. Defer setup during panic shouldn't crash for nil defer. + +package main + +func main() { + defer func() { + // This recover recovers the panic caused by the nil defer func + // g(). The original panic(1) was already aborted/replaced by this + // new panic, so when this recover is done, the program completes + // normally. + recover() + }() + f() +} + +func f() { + var g func() + defer g() + panic(1) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8048.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8048.go new file mode 100644 index 0000000000000000000000000000000000000000..577f60670fee79d7a4c689758540c4810029bd61 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8048.go @@ -0,0 +1,107 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8048. Incorrect handling of liveness when walking stack +// containing faulting frame. + +package main + +import "runtime" + +func main() { + test1() + test2() + test3() +} + +func test1() { + // test1f will panic without its own defer. + // The runtime.GC checks that we can walk the stack + // at that point and not get confused. + // The recover lets test1 exit normally. + defer func() { + runtime.GC() + recover() + }() + test1f() +} + +func test1f() { + // Because b == false, the if does not execute, + // so x == nil, so the println(*x) faults reading + // from nil. The compiler will lay out the code + // so that the if body occurs above the *x, + // so if the liveness info at the *x is used, it will + // find the liveness at the call to runtime.GC. + // It will think y is live, but y is uninitialized, + // and the runtime will crash detecting a bad slice. + // The runtime should see that there are no defers + // corresponding to this panicked frame and ignore + // the frame entirely. + var x *int + var b bool + if b { + y := make([]int, 1) + runtime.GC() + x = &y[0] + } + println(*x) +} + +func test2() { + // Same as test1, but the fault happens in the function with the defer. + // The runtime should see the defer and garbage collect the frame + // as if the PC were immediately after the defer statement. + defer func() { + runtime.GC() + recover() + }() + var x *int + var b bool + if b { + y := make([]int, 1) + runtime.GC() + x = &y[0] + } + println(*x) +} + +func test3() { + // Like test1 but avoid array index, which does not + // move to end of function on ARM. + defer func() { + runtime.GC() + recover() + }() + test3setup() + test3f() +} + +func test3setup() { + var x uintptr + var b bool + b = true + if b { + y := uintptr(123) + runtime.GC() + x = y + } + runtime.GC() + globl = x +} + +var globl uintptr + +func test3f() { + var x *int + var b bool + if b { + y := new(int) + runtime.GC() + x = y + } + println(*x) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8060.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8060.go new file mode 100644 index 0000000000000000000000000000000000000000..ec52659e6eaf93f5d5ba73432fbcee82bcd54e2e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8060.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8060: internal compiler error. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8073.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8073.go new file mode 100644 index 0000000000000000000000000000000000000000..d47481cd822e21657d8b9dd16948744b0d61334e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8073.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8073. +// was "internal compiler error: overflow: float64 integer constant" + +package main + +func main() { + var x int + _ = float64(x * 0) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8074.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8074.go new file mode 100644 index 0000000000000000000000000000000000000000..604a4f924e3117a066ac42c745ff472049516245 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8074.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8074. +// was "cannot take the address of 1" + +package main + +func main() { + a := make([]byte, 10) + m := make(map[float64][]byte) + go copy(a, m[1.0]) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8076.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8076.go new file mode 100644 index 0000000000000000000000000000000000000000..543ccc130182b93c31598d365838615feb171881 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8076.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8076. nilwalkfwd walked forward forever +// on the instruction loop following the dereference. + +package main + +func main() { + _ = *(*int)(nil) +L: + _ = 0 + goto L +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8079.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8079.go new file mode 100644 index 0000000000000000000000000000000000000000..994999bf6fbfb5d13c8942d3794fe03310f5f9b5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8079.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8079: gccgo crashes when compiling interface with blank type name. + +package p + +type _ interface{} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8132.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8132.go new file mode 100644 index 0000000000000000000000000000000000000000..b28a84cd5a7e2870668c1c4973f0ebe227a5f309 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8132.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8132. stack walk handling of panic stack was confused +// about what was legal. + +package main + +import "runtime" + +var p *int + +func main() { + func() { + defer func() { + runtime.GC() + recover() + }() + var x [8192]byte + func(x [8192]byte) { + defer func() { + if err := recover(); err != nil { + println(*p) + } + }() + println(*p) + }(x) + }() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8139.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8139.go new file mode 100644 index 0000000000000000000000000000000000000000..6e5607d22f8099af4297f0a9f48ac5b4c1f78adf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8139.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8139. The x.(T) assertions used to write 1 (unexpected) +// return byte for the 0-byte return value T. + +package main + +import "fmt" + +type T struct{} + +func (T) M() {} + +type M interface { + M() +} + +var e interface{} = T{} +var i M = T{} +var b bool + +func f1() int { + if b { + return f1() // convince inliner not to inline + } + z := 0x11223344 + _ = e.(T) + return z +} + +func f2() int { + if b { + return f1() // convince inliner not to inline + } + z := 0x11223344 + _ = i.(T) + return z +} + +func main() { + x := f1() + y := f2() + if x != 0x11223344 || y != 0x11223344 { + fmt.Printf("BUG: x=%#x y=%#x, want 0x11223344 for both\n", x, y) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8154.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8154.go new file mode 100644 index 0000000000000000000000000000000000000000..3ffad34aeea2733f1b24803d6025026368c6fc93 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8154.go @@ -0,0 +1,14 @@ +// compile + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8154: cmd/5g: ICE in walkexpr walk.c + +package main + +func main() { + c := make(chan int) + _ = [1][]func(){[]func(){func() { <-c }}} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8155.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8155.go new file mode 100644 index 0000000000000000000000000000000000000000..56a67389206729d324a7ca8b5d21393515fa2116 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8155.go @@ -0,0 +1,48 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8155. +// Alignment of stack prologue zeroing was wrong on 64-bit Native Client +// (because of 32-bit pointers). + +package main + +import "runtime" + +func bad(b bool) uintptr { + var p **int + var x1 uintptr + x1 = 1 + if b { + var x [11]*int + p = &x[0] + } + if b { + var x [1]*int + p = &x[0] + } + runtime.GC() + if p != nil { + x1 = uintptr(**p) + } + return x1 +} + +func poison() uintptr { + runtime.GC() + var x [20]uintptr + var s uintptr + for i := range x { + x[i] = uintptr(i+1) + s += x[i] + } + return s +} + +func main() { + poison() + bad(false) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8158.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8158.go new file mode 100644 index 0000000000000000000000000000000000000000..150b338bbe74d7e0bb77e0200fb9a82f55ceacd0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8158.go @@ -0,0 +1,41 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "runtime" + "time" +) + +func main() { + c := make(chan bool, 1) + go f1(c) + <-c + time.Sleep(10 * time.Millisecond) + go f2(c) + <-c +} + +func f1(done chan bool) { + defer func() { + recover() + done <- true + runtime.Goexit() // left stack-allocated Panic struct on gp->panic stack + }() + panic("p") +} + +func f2(done chan bool) { + defer func() { + recover() + done <- true + runtime.Goexit() + }() + time.Sleep(10 * time.Millisecond) // overwrote Panic struct with Timer struct + runtime.GC() // walked gp->panic list, found mangled Panic struct, crashed + panic("p") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8183.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8183.go new file mode 100644 index 0000000000000000000000000000000000000000..fe2dff786c4288213c9bcb4f4bfdb1d8b0405892 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8183.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Tests correct reporting of line numbers for errors involving iota, +// Issue #8183. +package foo + +const ( + ok = byte(iota + 253) + bad + barn + bard // ERROR "constant 256 overflows byte|integer constant overflow|cannot convert" +) + +const ( + c = len([1 - iota]int{}) + d + e // ERROR "array bound must be non-negative|negative array bound|invalid array length" + f // ERROR "array bound must be non-negative|negative array bound|invalid array length" +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8280.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8280.go new file mode 100644 index 0000000000000000000000000000000000000000..91256c852dfac513db59ac2c913aa4689dfd86b7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8280.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8280: cannot import package exporting a func var returning a result named _ + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8311.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8311.go new file mode 100644 index 0000000000000000000000000000000000000000..b5fd5daea1d7dd49ec20daabeb06350ab5c2cf8e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8311.go @@ -0,0 +1,16 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8311. +// error for x++ should say x++ not x += 1 + +package p + +func f() { + var x []byte + x++ // ERROR "invalid operation: x[+][+]|non-numeric type" + +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8325.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8325.go new file mode 100644 index 0000000000000000000000000000000000000000..6b0fc2570e38d146c5e290034759d55779e00745 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8325.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8325: corrupted byte operations during optimization +// pass. + +package main + +const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +func main() { + var bytes = []byte{10, 20, 30, 40, 50} + + for i, b := range bytes { + bytes[i] = alphanum[b%byte(len(alphanum))] + } + + for _, b := range bytes { + switch { + case '0' <= b && b <= '9', + 'A' <= b && b <= 'Z': + default: + println("found a bad character", string(b)) + panic("BUG") + } + + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8336.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8336.go new file mode 100644 index 0000000000000000000000000000000000000000..419fdf16272653447b75627f58e2d3708f0a6170 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8336.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8336. Order of evaluation of receive channels in select. + +package main + +type X struct { + c chan int +} + +func main() { + defer func() { + recover() + }() + var x *X + select { + case <-x.c: // should fault and panic before foo is called + case <-foo(): + } +} + +func foo() chan int { + println("BUG: foo must not be called") + return make(chan int) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8347.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8347.go new file mode 100644 index 0000000000000000000000000000000000000000..6394a9581661b2f867ca21c87383bb7b1b53f7d8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8347.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + c := make(chan bool, 1) + ok := true + for i := 0; i < 12; i++ { + select { + case _, ok = <-c: + if i < 10 && !ok { + panic("BUG") + } + default: + } + if i < 10 && !ok { + panic("BUG") + } + if i >= 10 && ok { + close(c) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8385.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8385.go new file mode 100644 index 0000000000000000000000000000000000000000..f3d395e52175111f01a052b656929ed676c8acc9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8385.go @@ -0,0 +1,42 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8385: provide a more descriptive error when a method expression +// is called without a receiver. + +package main + +type Fooer interface { + Foo(i, j int) +} + +func f(x int) { +} + +type I interface { + M(int) +} +type T struct{} + +func (t T) M(x int) { +} + +func g() func(int) + +func main() { + Fooer.Foo(5, 6) // ERROR "not enough arguments in call to method expression Fooer.Foo|incompatible type|not enough arguments" + + var i I + var t *T + + g()() // ERROR "not enough arguments in call to g\(\)|not enough arguments" + f() // ERROR "not enough arguments in call to f|not enough arguments" + i.M() // ERROR "not enough arguments in call to i\.M|not enough arguments" + I.M() // ERROR "not enough arguments in call to method expression I\.M|not enough arguments" + t.M() // ERROR "not enough arguments in call to t\.M|not enough arguments" + T.M() // ERROR "not enough arguments in call to method expression T\.M|not enough arguments" + (*T).M() // ERROR "not enough arguments in call to method expression \(\*T\)\.M|not enough arguments" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8438.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8438.go new file mode 100644 index 0000000000000000000000000000000000000000..fcbb4f86ec1a71fdfe09476311a431b41e361c1b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8438.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check that we don't print duplicate errors for string -> +// array-literal conversion + +package main + +func main() { + _ = []byte{"foo"} // ERROR "cannot use|incompatible type|cannot convert" + _ = []int{"foo"} // ERROR "cannot use|incompatible type|cannot convert" + _ = []rune{"foo"} // ERROR "cannot use|incompatible type|cannot convert" + _ = []string{"foo"} // OK +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8440.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8440.go new file mode 100644 index 0000000000000000000000000000000000000000..1d9fa936c4c096c51cb9b03f2191f34bcb227760 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8440.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + n.foo = 6 // ERROR "undefined: n in n.foo|undefined name .*n|undefined: n" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8475.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8475.go new file mode 100644 index 0000000000000000000000000000000000000000..5b22067bfee6896fa2f0f6b37f7be696e987a332 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8475.go @@ -0,0 +1,25 @@ +// build + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8745: comma-ok assignments should produce untyped bool as 2nd result. + +package main + +type mybool bool + +func main() { + var ok mybool + _ = ok + + var i interface{} + _, ok = i.(int) + + var m map[int]int + _, ok = m[0] + + var c chan int + _, ok = <-c +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8501.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8501.go new file mode 100644 index 0000000000000000000000000000000000000000..90ba096be3719ccfd5040f6a812a85ab137445ce --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8501.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T struct { + f float64 +} + +var t T + +func F() { + _ = complex(1.0) // ERROR "invalid operation|not enough arguments" + _ = complex(t.f) // ERROR "invalid operation|not enough arguments" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8507.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8507.go new file mode 100644 index 0000000000000000000000000000000000000000..6b513baf27dbb74389fef068db63c0c346f60b32 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8507.go @@ -0,0 +1,16 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8507 +// used to call algtype on invalid recursive type and get into infinite recursion + +package p + +type T struct{ T } // ERROR "invalid recursive type.*T" + +func f() { + println(T{} == T{}) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8606.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8606.go new file mode 100644 index 0000000000000000000000000000000000000000..6bac02a1da71f271dc6b16c610431c6c2a8fe08b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8606.go @@ -0,0 +1,106 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check to make sure that we compare fields in order. See issue 8606. + +package main + +import "fmt" + +func main() { + type A [2]interface{} + type A2 [6]interface{} + type S struct{ x, y interface{} } + type S2 struct{ x, y, z, a, b, c interface{} } + type T1 struct { + i interface{} + a int64 + j interface{} + } + type T2 struct { + i interface{} + a, b, c int64 + j interface{} + } + type T3 struct { + i interface{} + s string + j interface{} + } + type S3 struct { + f any + i int + } + type S4 struct { + a [1000]byte + b any + } + b := []byte{1} + s1 := S3{func() {}, 0} + s2 := S3{func() {}, 1} + + for _, test := range []struct { + panic bool + a, b interface{} + }{ + {false, A{1, b}, A{2, b}}, + {true, A{b, 1}, A{b, 2}}, + {false, A{1, b}, A{"2", b}}, + {true, A{b, 1}, A{b, "2"}}, + + {false, A2{1, b}, A2{2, b}}, + {true, A2{b, 1}, A2{b, 2}}, + {false, A2{1, b}, A2{"2", b}}, + {true, A2{b, 1}, A2{b, "2"}}, + + {false, S{1, b}, S{2, b}}, + {true, S{b, 1}, S{b, 2}}, + {false, S{1, b}, S{"2", b}}, + {true, S{b, 1}, S{b, "2"}}, + + {false, S2{x: 1, y: b}, S2{x: 2, y: b}}, + {true, S2{x: b, y: 1}, S2{x: b, y: 2}}, + {false, S2{x: 1, y: b}, S2{x: "2", y: b}}, + {true, S2{x: b, y: 1}, S2{x: b, y: "2"}}, + + {true, T1{i: b, a: 1}, T1{i: b, a: 2}}, + {false, T1{a: 1, j: b}, T1{a: 2, j: b}}, + {true, T2{i: b, a: 1}, T2{i: b, a: 2}}, + {false, T2{a: 1, j: b}, T2{a: 2, j: b}}, + {true, T3{i: b, s: "foo"}, T3{i: b, s: "bar"}}, + {false, T3{s: "foo", j: b}, T3{s: "bar", j: b}}, + {true, T3{i: b, s: "fooz"}, T3{i: b, s: "bar"}}, + {false, T3{s: "fooz", j: b}, T3{s: "bar", j: b}}, + {true, A{s1, s2}, A{s2, s1}}, + {true, s1, s2}, + {false, S4{[1000]byte{0}, func() {}}, S4{[1000]byte{1}, func() {}}}, + } { + f := func() { + defer func() { + if recover() != nil { + panic(fmt.Sprintf("comparing %#v and %#v panicked", test.a, test.b)) + } + }() + if test.a == test.b { + panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b)) + } + } + if test.panic { + shouldPanic(fmt.Sprintf("comparing %#v and %#v did not panic", test.a, test.b), f) + } else { + f() // should not panic + } + } +} + +func shouldPanic(name string, f func()) { + defer func() { + if recover() == nil { + panic(name) + } + }() + f() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8606b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8606b.go new file mode 100644 index 0000000000000000000000000000000000000000..6a56c0df89c8e3398dd45f119f8534eca4daf9d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8606b.go @@ -0,0 +1,71 @@ +// run + +//go:build linux || darwin + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is an optimization check. We want to make sure that we compare +// string lengths, and other scalar fields, before checking string +// contents. There's no way to verify this in the language, and +// codegen tests in test/codegen can't really detect ordering +// optimizations like this. Instead, we generate invalid strings with +// bad backing store pointers but nonzero length, so we can check that +// the backing store never gets compared. +// +// We use two different bad strings so that pointer comparisons of +// backing store pointers fail. + +package main + +import ( + "fmt" + "reflect" + "syscall" + "unsafe" +) + +type SI struct { + s string + i int +} + +type SS struct { + s string + t string +} + +func main() { + bad1 := "foo" + bad2 := "foo" + + p := syscall.Getpagesize() + b, err := syscall.Mmap(-1, 0, p, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE) + if err != nil { + panic(err) + } + err = syscall.Mprotect(b, syscall.PROT_NONE) + if err != nil { + panic(err) + } + // write inaccessible pointers as the data fields of bad1 and bad2. + (*reflect.StringHeader)(unsafe.Pointer(&bad1)).Data = uintptr(unsafe.Pointer(&b[0])) + (*reflect.StringHeader)(unsafe.Pointer(&bad2)).Data = uintptr(unsafe.Pointer(&b[1])) + + for _, test := range []struct { + a, b interface{} + }{ + {SI{s: bad1, i: 1}, SI{s: bad2, i: 2}}, + {SS{s: bad1, t: "a"}, SS{s: bad2, t: "aa"}}, + {SS{s: "a", t: bad1}, SS{s: "b", t: bad2}}, + // This one would panic because the length of both strings match, and we check + // the body of the bad strings before the body of the good strings. + //{SS{s: bad1, t: "a"}, SS{s: bad2, t: "b"}}, + } { + if test.a == test.b { + panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b)) + } + } + +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8612.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8612.go new file mode 100644 index 0000000000000000000000000000000000000000..2a622f4cb25c1a8a4c48a920bf9ec83ac88ad440 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8612.go @@ -0,0 +1,34 @@ +//compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Gccgo had a bug comparing a struct or array value with an interface +// values, when the struct or array was not addressable. + +package p + +type A [10]int + +type S struct { + i int +} + +func F1() S { + return S{0} +} + +func F2() A { + return A{} +} + +func Cmp(v interface{}) bool { + if F1() == v { + return true + } + if F2() == v { + return true + } + return false +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8613.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8613.go new file mode 100644 index 0000000000000000000000000000000000000000..ffa75a48a09f08ca0bd85cbb6fe634767218a3bd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8613.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var out int +var zero int + +func main() { + wantPanic("test1", func() { + out = 1 / zero + }) + wantPanic("test2", func() { + _ = 1 / zero + }) + wantPanic("test3", func() { + v := 0 + _ = 1 / v + }) + wantPanic("test4", func() { divby(0) }) +} + +func wantPanic(test string, fn func()) { + defer func() { + if e := recover(); e == nil { + panic(test + ": expected panic") + } + }() + fn() +} + +//go:noinline +func divby(v int) { + _ = 1 / v +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8620.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8620.go new file mode 100644 index 0000000000000000000000000000000000000000..47546045eaf144c68d3fa3abb24ddb825e388c55 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8620.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8620. Used to fail with -race. + +package main + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func test(s1, s2 []struct{}) { + n := min(len(s1), len(s2)) + if copy(s1, s2) != n { + panic("bad copy result") + } +} + +func main() { + var b [100]struct{} + test(b[:], b[:]) + test(b[1:], b[:]) + test(b[:], b[2:]) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8745.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8745.go new file mode 100644 index 0000000000000000000000000000000000000000..c2d00a7ebd4be0a802cd4aa466a1bb6a149bc681 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8745.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check that the error says s[2] is a byte, not a uint8. + +package p + +func f(s string) { + var _ float64 = s[2] // ERROR "cannot use.*type byte.*as type float64|cannot use .* as float64 value" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8761.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8761.go new file mode 100644 index 0000000000000000000000000000000000000000..e5130e1ff5ca92edad3f7d950093be9ced6d00b0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8761.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8761 +// used to confuse code generator into using temporary before initialization. +// caused 'variable live at entry' error in liveness analysis. + +package p + +func f1() { + type C chan int + _ = [1][]C{[]C{make(chan int)}} +} + +func f2() { + type C interface{} + _ = [1][]C{[]C{recover()}} +} + +func f3() { + type C *int + _ = [1][]C{[]C{new(int)}} +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8836.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8836.go new file mode 100644 index 0000000000000000000000000000000000000000..039b9c7eb3b3b34e61ffec3e45a3022645bc80b3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8836.go @@ -0,0 +1,24 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Checking that line number is correct in error message. + +package main + +type Cint int + +func foobar(*Cint, Cint, Cint, *Cint) + +func main() { + a := Cint(1) + + foobar( + &a, + 0, + 0, + 42, // ERROR ".*" + ) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue887.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue887.go new file mode 100644 index 0000000000000000000000000000000000000000..b68ba6997f84d85d8cbfc4fa9ada403916bbc018 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue887.go @@ -0,0 +1,36 @@ +// compile + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Used to leak registers on 8g. + +package p + +func f(x byte, y uint64) { + var r byte + switch y { + case 1: + r = x << y // '>>' triggers it too + case 2: + r = x << y + case 3: + r = x << y + case 4: + r = x << y + case 5: + r = x << y + case 6: + r = x << y + case 7: + r = x << y + case 8: + r = x << y + case 9: + r = x << y + case 10: + r = x << y + } + _ = r +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8947.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8947.go new file mode 100644 index 0000000000000000000000000000000000000000..703207db39fbab96157defb53d3ceeff8dcc3c4b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8947.go @@ -0,0 +1,53 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Some uses of zeroed constants in non-assignment +// expressions broke with our more aggressive zeroing +// of assignments (internal compiler errors). + +package main + +func f1() { + type T [2]int + p := T{0, 1} + switch p { + case T{0, 0}: + panic("wrong1") + case T{0, 1}: + // ok + default: + panic("wrong2") + } + + if p == (T{0, 0}) { + panic("wrong3") + } else if p == (T{0, 1}) { + // ok + } else { + panic("wrong4") + } +} + +type T struct { + V int +} + +var X = T{}.V + +func f2() { + var x = T{}.V + if x != 0 { + panic("wrongx") + } + if X != 0 { + panic("wrongX") + } +} + +func main() { + f1() + f2() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue8961.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue8961.go new file mode 100644 index 0000000000000000000000000000000000000000..22b0f0410a92e07ec65d0f20c8f292a4299365ee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue8961.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 8961. Empty composite literals to small globals were not filled in +package main + +type small struct { a int } +var foo small + +func main() { + foo.a = 1 + foo = small{} + if foo.a != 0 { + println("expected foo.a to be 0, was", foo.a) + panic("composite literal not filled in") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9006.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9006.go new file mode 100644 index 0000000000000000000000000000000000000000..a61574b6f028cddd94092321f2a0c49865e44607 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9006.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T1 struct { + X int +} + +func NewT1(x int) T1 { return T1{x} } + +type T2 int + +func NewT2(x int) T2 { return T2(x) } + +func main() { + switch (T1{}) { + case NewT1(1): + panic("bad1") + case NewT1(0): + // ok + default: + panic("bad2") + } + + switch T2(0) { + case NewT2(2): + panic("bad3") + case NewT2(0): + // ok + default: + panic("bad4") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9017.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9017.go new file mode 100644 index 0000000000000000000000000000000000000000..5659785c3f0957f6dddae2cba368abe50bd81e74 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9017.go @@ -0,0 +1,57 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9017: Method selector shouldn't automatically dereference a named pointer type. + +package main + +type T struct{ x int } + +func (T) mT() {} + +type S struct { + T +} + +func (S) mS() {} + +type P *S + +type I interface { + mT() +} + +func main() { + var s S + s.T.mT() + s.mT() // == s.T.mT() + + var i I + _ = i + i = s.T + i = s + + var ps = &s + ps.mS() + ps.T.mT() + ps.mT() // == ps.T.mT() + + i = ps.T + i = ps + + var p P = ps + (*p).mS() + p.mS() // ERROR "undefined" + + i = *p + i = p // ERROR "cannot use|incompatible types" + + p.T.mT() + p.mT() // ERROR "undefined" + + i = p.T + i = p // ERROR "cannot use|incompatible types" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9036.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9036.go new file mode 100644 index 0000000000000000000000000000000000000000..e3d394f7f299cdfb1ed5f242c0751dbe555fc2a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9036.go @@ -0,0 +1,31 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Expects to see error messages on 'p' exponents +// for non-hexadecimal floats. + +package main + +import "fmt" + +const ( + x1 = 1.1 // float + x2 = 1e10 // float + x3 = 0x1e10 // integer (e is a hex digit) +) + +const x4 = 0x1p10 // valid hexadecimal float +const x5 = 1p10 // ERROR "'p' exponent requires hexadecimal mantissa|invalid prefix" +const x6 = 0P0 // ERROR "'P' exponent requires hexadecimal mantissa|invalid prefix" + +func main() { + fmt.Printf("%g %T\n", x1, x1) + fmt.Printf("%g %T\n", x2, x2) + fmt.Printf("%g %T\n", x3, x3) + fmt.Printf("%g %T\n", x4, x4) + fmt.Printf("%g %T\n", x5, x5) + fmt.Printf("%g %T\n", x6, x6) +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9076.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9076.go new file mode 100644 index 0000000000000000000000000000000000000000..1613d5ede39aa34ef27ee92afdcaaf8009f49990 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9076.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9076: cmd/gc shows computed values in error messages instead of original expression. + +package main + +import "unsafe" + +const Hundred = 100 +var _ int32 = 100/unsafe.Sizeof(int(0)) + 1 // ERROR "100 \/ unsafe.Sizeof\(int\(0\)\) \+ 1|incompatible type" +var _ int32 = Hundred/unsafe.Sizeof(int(0)) + 1 // ERROR "Hundred \/ unsafe.Sizeof\(int\(0\)\) \+ 1|incompatible type" diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9083.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9083.go new file mode 100644 index 0000000000000000000000000000000000000000..26d4d0f7656c50d2463caf99ef9b3097361ff64c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9083.go @@ -0,0 +1,23 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9083: map/chan error messages show non-explicit capacity. + +package main + +// untyped constant +const zero = 0 + +func main() { + var x int + _ = x + x = make(map[int]int) // ERROR "cannot use make\(map\[int\]int\)|incompatible" + x = make(map[int]int, 0) // ERROR "cannot use make\(map\[int\]int, 0\)|incompatible" + x = make(map[int]int, zero) // ERROR "cannot use make\(map\[int\]int, zero\)|incompatible" + x = make(chan int) // ERROR "cannot use make\(chan int\)|incompatible" + x = make(chan int, 0) // ERROR "cannot use make\(chan int, 0\)|incompatible" + x = make(chan int, zero) // ERROR "cannot use make\(chan int, zero\)|incompatible" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9110.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9110.go new file mode 100644 index 0000000000000000000000000000000000000000..086be772be6cd6f1b074433e4fe9f84dfd1a8502 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9110.go @@ -0,0 +1,91 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Scenario that used to leak arbitrarily many SudoG structs. +// See golang.org/issue/9110. + +package main + +import ( + "runtime" + "runtime/debug" + "sync" + "time" +) + +func main() { + runtime.GOMAXPROCS(1) + debug.SetGCPercent(1000000) // only GC when we ask for GC + + var stats, stats1, stats2 runtime.MemStats + + release := func() {} + for i := 0; i < 20; i++ { + if i == 10 { + // Should be warmed up by now. + runtime.ReadMemStats(&stats1) + } + + c := make(chan int) + for i := 0; i < 10; i++ { + go func() { + select { + case <-c: + case <-c: + case <-c: + } + }() + } + time.Sleep(1 * time.Millisecond) + release() + + close(c) // let select put its sudog's into the cache + time.Sleep(1 * time.Millisecond) + + // pick up top sudog + var cond1 sync.Cond + var mu1 sync.Mutex + cond1.L = &mu1 + go func() { + mu1.Lock() + cond1.Wait() + mu1.Unlock() + }() + time.Sleep(1 * time.Millisecond) + + // pick up next sudog + var cond2 sync.Cond + var mu2 sync.Mutex + cond2.L = &mu2 + go func() { + mu2.Lock() + cond2.Wait() + mu2.Unlock() + }() + time.Sleep(1 * time.Millisecond) + + // put top sudog back + cond1.Broadcast() + time.Sleep(1 * time.Millisecond) + + // drop cache on floor + runtime.GC() + + // release cond2 after select has gotten to run + release = func() { + cond2.Broadcast() + time.Sleep(1 * time.Millisecond) + } + } + + runtime.GC() + + runtime.ReadMemStats(&stats2) + + if int(stats2.HeapObjects)-int(stats1.HeapObjects) > 20 { // normally at most 1 or 2; was 300 with leak + print("BUG: object leak: ", stats.HeapObjects, " -> ", stats1.HeapObjects, " -> ", stats2.HeapObjects, "\n") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9321.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9321.go new file mode 100644 index 0000000000000000000000000000000000000000..2b2807a7b23207a64617e13ddb0c80fc2925be6f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9321.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "bytes" + "runtime" + "runtime/pprof" + "sync" +) + +func test() { + var wg sync.WaitGroup + wg.Add(2) + test := func() { + for i := 0; i < 10; i++ { + buf := &bytes.Buffer{} + pprof.Lookup("goroutine").WriteTo(buf, 2) + } + wg.Done() + } + + go test() + go test() + wg.Wait() +} + +func main() { + runtime.GOMAXPROCS(4) + for i := 0; i < 10; i++ { + test() + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9355.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9355.go new file mode 100644 index 0000000000000000000000000000000000000000..4e6cbf0395e7ff45aed995702bf35f63ea4b9f29 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9355.go @@ -0,0 +1,64 @@ +// run + +//go:build !js && !wasip1 && gc + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "regexp" +) + +func main() { + err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) + check(err) + + f, err := ioutil.TempFile("", "issue9355-*.o") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + f.Close() + + out := run("go", "tool", "compile", "-p=p", "-o", f.Name(), "-S", "a.go") + os.Remove(f.Name()) + + // 6g/8g print the offset as dec, but 5g/9g print the offset as hex. + patterns := []string{ + `rel 0\+\d t=R_ADDR p\.x\+8\r?\n`, // y = &x.b + `rel 0\+\d t=R_ADDR p\.x\+(28|1c)\r?\n`, // z = &x.d.q + `rel 0\+\d t=R_ADDR p\.b\+5\r?\n`, // c = &b[5] + `rel 0\+\d t=R_ADDR p\.x\+(88|58)\r?\n`, // w = &x.f[3].r + } + for _, p := range patterns { + if ok, err := regexp.Match(p, out); !ok || err != nil { + println(string(out)) + panic("can't find pattern " + p) + } + } +} + +func run(cmd string, args ...string) []byte { + out, err := exec.Command(cmd, args...).CombinedOutput() + if err != nil { + fmt.Println(string(out)) + fmt.Println(err) + os.Exit(1) + } + return out +} + +func check(err error) { + if err != nil { + fmt.Println("BUG:", err) + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9370.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9370.go new file mode 100644 index 0000000000000000000000000000000000000000..1a4510316dffaca59838d9546914e1f2274e5a24 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9370.go @@ -0,0 +1,127 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify that concrete/interface comparisons are +// typechecked correctly by the compiler. + +package main + +type I interface { + Method() +} + +type C int + +func (C) Method() {} + +type G func() + +func (G) Method() {} + +var ( + e interface{} + i I + c C + n int + f func() + g G +) + +var ( + _ = e == c + _ = e != c + _ = e >= c // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + _ = c == e + _ = c != e + _ = c >= e // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + + _ = i == c + _ = i != c + _ = i >= c // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + _ = c == i + _ = c != i + _ = c >= i // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + + _ = e == n + _ = e != n + _ = e >= n // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + _ = n == e + _ = n != e + _ = n >= e // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" + + // i and n are not assignable to each other + _ = i == n // ERROR "invalid operation.*mismatched types|incompatible types" + _ = i != n // ERROR "invalid operation.*mismatched types|incompatible types" + _ = i >= n // ERROR "invalid operation.*mismatched types|incompatible types" + _ = n == i // ERROR "invalid operation.*mismatched types|incompatible types" + _ = n != i // ERROR "invalid operation.*mismatched types|incompatible types" + _ = n >= i // ERROR "invalid operation.*mismatched types|incompatible types" + + _ = e == 1 + _ = e != 1 + _ = e >= 1 // ERROR "invalid operation.*not defined|invalid comparison" + _ = 1 == e + _ = 1 != e + _ = 1 >= e // ERROR "invalid operation.*not defined|invalid comparison" + + _ = i == 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + _ = i != 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + _ = i >= 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + _ = 1 == i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + _ = 1 != i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + _ = 1 >= i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" + + _ = e == f // ERROR "invalid operation.*not defined|invalid operation" + _ = e != f // ERROR "invalid operation.*not defined|invalid operation" + _ = e >= f // ERROR "invalid operation.*not defined|invalid comparison" + _ = f == e // ERROR "invalid operation.*not defined|invalid operation" + _ = f != e // ERROR "invalid operation.*not defined|invalid operation" + _ = f >= e // ERROR "invalid operation.*not defined|invalid comparison" + + _ = i == f // ERROR "invalid operation.*mismatched types|incompatible types" + _ = i != f // ERROR "invalid operation.*mismatched types|incompatible types" + _ = i >= f // ERROR "invalid operation.*mismatched types|incompatible types" + _ = f == i // ERROR "invalid operation.*mismatched types|incompatible types" + _ = f != i // ERROR "invalid operation.*mismatched types|incompatible types" + _ = f >= i // ERROR "invalid operation.*mismatched types|incompatible types" + + _ = e == g // ERROR "invalid operation.*not defined|invalid operation" + _ = e != g // ERROR "invalid operation.*not defined|invalid operation" + _ = e >= g // ERROR "invalid operation.*not defined|invalid comparison" + _ = g == e // ERROR "invalid operation.*not defined|invalid operation" + _ = g != e // ERROR "invalid operation.*not defined|invalid operation" + _ = g >= e // ERROR "invalid operation.*not defined|invalid comparison" + + _ = i == g // ERROR "invalid operation.*not defined|invalid operation" + _ = i != g // ERROR "invalid operation.*not defined|invalid operation" + _ = i >= g // ERROR "invalid operation.*not defined|invalid comparison" + _ = g == i // ERROR "invalid operation.*not defined|invalid operation" + _ = g != i // ERROR "invalid operation.*not defined|invalid operation" + _ = g >= i // ERROR "invalid operation.*not defined|invalid comparison" + + _ = _ == e // ERROR "cannot use .*_.* as value" + _ = _ == i // ERROR "cannot use .*_.* as value" + _ = _ == c // ERROR "cannot use .*_.* as value" + _ = _ == n // ERROR "cannot use .*_.* as value" + _ = _ == f // ERROR "cannot use .*_.* as value" + _ = _ == g // ERROR "cannot use .*_.* as value" + + _ = e == _ // ERROR "cannot use .*_.* as value" + _ = i == _ // ERROR "cannot use .*_.* as value" + _ = c == _ // ERROR "cannot use .*_.* as value" + _ = n == _ // ERROR "cannot use .*_.* as value" + _ = f == _ // ERROR "cannot use .*_.* as value" + _ = g == _ // ERROR "cannot use .*_.* as value" + + _ = _ == _ // ERROR "cannot use .*_.* as value" + + _ = e ^ c // ERROR "invalid operation.*mismatched types|incompatible types" + _ = c ^ e // ERROR "invalid operation.*mismatched types|incompatible types" + _ = 1 ^ e // ERROR "invalid operation.*mismatched types|incompatible types" + _ = e ^ 1 // ERROR "invalid operation.*mismatched types|incompatible types" + _ = 1 ^ c + _ = c ^ 1 +) diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9432.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9432.go new file mode 100644 index 0000000000000000000000000000000000000000..3df3b9097b57ed67fa7196aa664411b3f4f8f4d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9432.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// gc used to recurse infinitely when dowidth is applied +// to a broken recursive type again. +// See golang.org/issue/9432. +package p + +type foo struct { // ERROR "invalid recursive type|cycle" + bar foo + blah foo +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9521.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9521.go new file mode 100644 index 0000000000000000000000000000000000000000..a029ec145e9637dfa494fb82d8b3626d1ed3412c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9521.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that an incorrect use of the blank identifier is caught. +// Does not compile. + +package main + +func f() (_, _ []int) { return } +func g() (x []int, y float64) { return } + +func main() { + _ = append(f()) // ERROR "cannot use \[\]int value as type int in append|cannot use.*type \[\]int.*to append" + _ = append(g()) // ERROR "cannot use float64 value as type int in append|cannot use.*type float64.*to append" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9537.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9537.go new file mode 100644 index 0000000000000000000000000000000000000000..ac2d41b1234ec8f03ca9a4d62b3c8a00b7fa7852 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9537.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9537: Compiler does not run escape analysis on an inlined +// generated method wrapper. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9604.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9604.go new file mode 100644 index 0000000000000000000000000000000000000000..cd9e9e49e58261851db156c44a58a288a4e853d2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9604.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var x uint16 = 0xffff +var y uint16 = 0xfffe +var a uint16 = 0x7000 +var b uint16 = 0x9000 + +func main() { + // Make sure we truncate to smaller-width types after evaluating expressions. + // This is a problem for arm where there is no 16-bit comparison op. + if ^x != 0 { + panic("^uint16(0xffff) != 0") + } + if ^y != 1 { + panic("^uint16(0xfffe) != 1") + } + if -x != 1 { + panic("-uint16(0xffff) != 1") + } + if a+b != 0 { + panic("0x7000+0x9000 != 0") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9604b.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9604b.go new file mode 100644 index 0000000000000000000000000000000000000000..0033a6ff951fee85a9f400bd499633888949b2de --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9604b.go @@ -0,0 +1,180 @@ +// runoutput + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// terribly slow on wasm +//go:build !wasm + +package main + +import ( + "fmt" + "math/big" + "unsafe" +) + +var one = big.NewInt(1) + +type _type struct { + name string + bits uint + signed bool +} + +// testvalues returns a list of all test values for this type. +func (t *_type) testvalues() []*big.Int { + var a []*big.Int + + a = append(a, big.NewInt(0)) + a = append(a, big.NewInt(1)) + a = append(a, big.NewInt(2)) + if t.signed { + a = append(a, big.NewInt(-1)) + a = append(a, big.NewInt(-2)) + r := big.NewInt(1) + a = append(a, r.Lsh(r, t.bits-1).Sub(r, big.NewInt(1))) + r = big.NewInt(1) + a = append(a, r.Lsh(r, t.bits-1).Sub(r, big.NewInt(2))) + r = big.NewInt(1) + a = append(a, r.Lsh(r, t.bits-1).Neg(r)) + r = big.NewInt(1) + a = append(a, r.Lsh(r, t.bits-1).Neg(r).Add(r, big.NewInt(1))) + } else { + r := big.NewInt(1) + a = append(a, r.Lsh(r, t.bits).Sub(r, big.NewInt(1))) + r = big.NewInt(1) + a = append(a, r.Lsh(r, t.bits).Sub(r, big.NewInt(2))) + } + return a +} + +// trunc truncates a value to the range of the given type. +func (t *_type) trunc(x *big.Int) *big.Int { + r := new(big.Int) + m := new(big.Int) + m.Lsh(one, t.bits) + m.Sub(m, one) + r.And(x, m) + if t.signed && r.Bit(int(t.bits)-1) == 1 { + m.Neg(one) + m.Lsh(m, t.bits) + r.Or(r, m) + } + return r +} + +var types = []_type{ + _type{"byte", 8, false}, + _type{"int8", 8, true}, + _type{"uint8", 8, false}, + _type{"rune", 32, true}, + _type{"int16", 16, true}, + _type{"uint16", 16, false}, + _type{"int32", 32, true}, + _type{"uint32", 32, false}, + _type{"int64", 64, true}, + _type{"uint64", 64, false}, + _type{"int", 8 * uint(unsafe.Sizeof(int(0))), true}, + _type{"uint", 8 * uint(unsafe.Sizeof(uint(0))), false}, + _type{"uintptr", 8 * uint(unsafe.Sizeof((*byte)(nil))), false}, +} + +type binop struct { + name string + eval func(x, y *big.Int) *big.Int +} + +var binops = []binop{ + binop{"+", func(x, y *big.Int) *big.Int { return new(big.Int).Add(x, y) }}, + binop{"-", func(x, y *big.Int) *big.Int { return new(big.Int).Sub(x, y) }}, + binop{"*", func(x, y *big.Int) *big.Int { return new(big.Int).Mul(x, y) }}, + binop{"/", func(x, y *big.Int) *big.Int { return new(big.Int).Quo(x, y) }}, + binop{"%", func(x, y *big.Int) *big.Int { return new(big.Int).Rem(x, y) }}, + binop{"&", func(x, y *big.Int) *big.Int { return new(big.Int).And(x, y) }}, + binop{"|", func(x, y *big.Int) *big.Int { return new(big.Int).Or(x, y) }}, + binop{"^", func(x, y *big.Int) *big.Int { return new(big.Int).Xor(x, y) }}, + binop{"&^", func(x, y *big.Int) *big.Int { return new(big.Int).AndNot(x, y) }}, +} + +type unop struct { + name string + eval func(x *big.Int) *big.Int +} + +var unops = []unop{ + unop{"+", func(x *big.Int) *big.Int { return new(big.Int).Set(x) }}, + unop{"-", func(x *big.Int) *big.Int { return new(big.Int).Neg(x) }}, + unop{"^", func(x *big.Int) *big.Int { return new(big.Int).Not(x) }}, +} + +type shiftop struct { + name string + eval func(x *big.Int, i uint) *big.Int +} + +var shiftops = []shiftop{ + shiftop{"<<", func(x *big.Int, i uint) *big.Int { return new(big.Int).Lsh(x, i) }}, + shiftop{">>", func(x *big.Int, i uint) *big.Int { return new(big.Int).Rsh(x, i) }}, +} + +// valname returns the name of n as can be used as part of a variable name. +func valname(n *big.Int) string { + s := fmt.Sprintf("%d", n) + if s[0] == '-' { + s = "neg" + s[1:] + } + return s +} + +func main() { + fmt.Println("package main") + + // We make variables to hold all the different values we'd like to use. + // We use global variables to prevent any constant folding. + for _, t := range types { + for _, n := range t.testvalues() { + fmt.Printf("var %s_%s %s = %d\n", t.name, valname(n), t.name, n) + } + } + + fmt.Println("func main() {") + + for _, t := range types { + // test binary ops + for _, op := range binops { + for _, x := range t.testvalues() { + for _, y := range t.testvalues() { + if (op.name == "/" || op.name == "%") && y.Sign() == 0 { + continue + } + r := t.trunc(op.eval(x, y)) + eqn := fmt.Sprintf("%s_%s %s %s_%s != %d", t.name, valname(x), op.name, t.name, valname(y), r) + fmt.Printf("\tif %s { println(\"bad: %s\") }\n", eqn, eqn) + } + } + } + // test unary ops + for _, op := range unops { + for _, x := range t.testvalues() { + r := t.trunc(op.eval(x)) + eqn := fmt.Sprintf("%s %s_%s != %d", op.name, t.name, valname(x), r) + fmt.Printf("\tif %s { println(\"bad: %s\") }\n", eqn, eqn) + } + } + // test shifts + for _, op := range shiftops { + for _, x := range t.testvalues() { + + for _, i := range []uint{0, 1, t.bits - 2, t.bits - 1, t.bits, t.bits + 1} { + r := t.trunc(op.eval(x, i)) + eqn := fmt.Sprintf("%s_%s %s %d != %d", t.name, valname(x), op.name, i, r) + fmt.Printf("\tif %s { println(\"bad: %s\") }\n", eqn, eqn) + } + } + } + } + + fmt.Println("}") +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9608.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9608.go new file mode 100644 index 0000000000000000000000000000000000000000..92592d76ee3f7481e12776fe0e78f464f1146613 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9608.go @@ -0,0 +1,14 @@ +// rundir + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9608: dead code elimination in switch statements. + +// This has to be done as a package rather than as a file, +// because run.go runs files with 'go run', which passes the +// -complete flag to compiler, causing it to complain about +// the intentionally unimplemented function fail. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9634.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9634.go new file mode 100644 index 0000000000000000000000000000000000000000..86e3e9a2dfd42d215610cf3155da2afd8f1677a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9634.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 9634: Structs are incorrectly unpacked when passed as an argument +// to append. + +package main + +func main() { + s := struct{ + t []int + u int + }{} + _ = append(s, 0) // ERROR "must be a slice|must be slice|not a slice" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9691.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9691.go new file mode 100644 index 0000000000000000000000000000000000000000..39c3dfa7ae4c5b1316c678b5bfa168a74612db20 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9691.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + s := "foo" + b := []byte(s) + m := make(map[string]int) + // Test that map index can be used in range + // and that slicebytetostringtmp is not used in this context. + for m[string(b)] = range s { + } + b[0] = 'b' + if m["foo"] != 2 { + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9731.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9731.go new file mode 100644 index 0000000000000000000000000000000000000000..9237d652ce7408cb5c7be33a5b27824a83e2cc36 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9731.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(x interface{}) { + switch x := x.(type) { + case int: + func() { + _ = x + }() + case map[int]int: + func() { + for range x { + } + }() + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9738.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9738.go new file mode 100644 index 0000000000000000000000000000000000000000..85319d70a72f12b3492990c48e109101c15c0116 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9738.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func F() (x int) { + defer func() { + if x != 42 { + println("BUG: x =", x) + } + }() + return 42 +} + +func main() { + F() +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9862.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9862.go new file mode 100644 index 0000000000000000000000000000000000000000..3572512651948d5512fd5faf5954cc9c9b778412 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9862.go @@ -0,0 +1,15 @@ +// skip + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var a [1<<31 - 1024]byte + +func main() { + if a[0] != 0 { + panic("bad array") + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/issue9862_run.go b/platform/dbops/binaries/go/go/test/fixedbugs/issue9862_run.go new file mode 100644 index 0000000000000000000000000000000000000000..8c5caa337349f32ea116d6535b29e216d3fcd681 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/issue9862_run.go @@ -0,0 +1,28 @@ +// run + +//go:build !nacl && !js && !wasip1 && gc + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check for compile or link error. + +package main + +import ( + "os/exec" + "strings" +) + +func main() { + out, err := exec.Command("go", "run", "fixedbugs/issue9862.go").CombinedOutput() + outstr := string(out) + if err == nil { + println("go run issue9862.go succeeded, should have failed\n", outstr) + return + } + if !strings.Contains(outstr, "symbol too large") { + println("go run issue9862.go gave unexpected error; want symbol too large:\n", outstr) + } +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/notinheap.go b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap.go new file mode 100644 index 0000000000000000000000000000000000000000..2188a38a143c14f9916c5b4fd9672e5974559608 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap.go @@ -0,0 +1,51 @@ +// errorcheck -+ + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test type-checking errors for go:notinheap. + +package p + +//go:notinheap +type nih struct{} + +type embed4 map[nih]int // ERROR "incomplete \(or unallocatable\) map key not allowed" + +type embed5 map[int]nih // ERROR "incomplete \(or unallocatable\) map value not allowed" + +type emebd6 chan nih // ERROR "chan of incomplete \(or unallocatable\) type not allowed" + +type okay1 *nih + +type okay2 []nih + +type okay3 func(x nih) nih + +type okay4 interface { + f(x nih) nih +} + +// Type conversions don't let you sneak past notinheap. + +type t1 struct{ x int } + +//go:notinheap +type t2 t1 + +//go:notinheap +type t3 byte + +//go:notinheap +type t4 rune + +var sink interface{} + +func i() { + sink = new(t1) // no error + sink = (*t2)(new(t1)) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)" + sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)" + sink = []t3("foo") // ERROR "cannot convert(.|\n)*t3 is incomplete \(or unallocatable\)" + sink = []t4("bar") // ERROR "cannot convert(.|\n)*t4 is incomplete \(or unallocatable\)" +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/notinheap2.go b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap2.go new file mode 100644 index 0000000000000000000000000000000000000000..cc1024ad5a5f920410c2834f255725cb8a8a1b3c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap2.go @@ -0,0 +1,85 @@ +// errorcheck -+ + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test walk errors for not-in-heap. + +//go:build cgo + +package p + +import "runtime/cgo" + +type nih struct { + _ cgo.Incomplete + next *nih +} + +// Global variables are okay. + +var x nih + +// Stack variables are not okay. + +func f() { + var y nih // ERROR "nih is incomplete \(or unallocatable\); stack allocation disallowed" + x = y +} + +// Heap allocation is not okay. + +var y *nih +var y2 *struct{ x nih } +var y3 *[1]nih +var z []nih +var w []nih +var n int +var sink interface{} + +type embed1 struct { // implicitly notinheap + x nih +} + +type embed2 [1]nih // implicitly notinheap + +type embed3 struct { // implicitly notinheap + x [1]nih +} + +// Type aliases inherit the go:notinheap-ness of the type they alias. +type nihAlias = nih + +type embedAlias1 struct { // implicitly notinheap + x nihAlias +} +type embedAlias2 [1]nihAlias // implicitly notinheap + +func g() { + y = new(nih) // ERROR "can't be allocated in Go" + y2 = new(struct{ x nih }) // ERROR "can't be allocated in Go" + y3 = new([1]nih) // ERROR "can't be allocated in Go" + z = make([]nih, 1) // ERROR "can't be allocated in Go" + z = append(z, x) // ERROR "can't be allocated in Go" + + sink = new(embed1) // ERROR "can't be allocated in Go" + sink = new(embed2) // ERROR "can't be allocated in Go" + sink = new(embed3) // ERROR "can't be allocated in Go" + sink = new(embedAlias1) // ERROR "can't be allocated in Go" + sink = new(embedAlias2) // ERROR "can't be allocated in Go" + + // Test for special case of OMAKESLICECOPY + x := make([]nih, n) // ERROR "can't be allocated in Go" + copy(x, z) + z = x +} + +// Writes don't produce write barriers. + +var p *nih + +//go:nowritebarrier +func h() { + y.next = p.next +} diff --git a/platform/dbops/binaries/go/go/test/fixedbugs/notinheap3.go b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap3.go new file mode 100644 index 0000000000000000000000000000000000000000..b442ed42cd6e36771c0894abd55b36691365f20d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/fixedbugs/notinheap3.go @@ -0,0 +1,80 @@ +// errorcheck -+ -0 -l -d=wb + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test write barrier elimination for notinheap. + +//go:build cgo + +package p + +import "runtime/cgo" + +type t1 struct { + x *nih + s []nih + y [1024]byte // Prevent write decomposition +} + +type t2 struct { + x *ih + s []ih + y [1024]byte +} + +type nih struct { + _ cgo.Incomplete + x uintptr +} + +type ih struct { // In-heap type + x uintptr +} + +var ( + v1 t1 + v2 t2 + + v1s []t1 + v2s []t2 +) + +func f() { + // Test direct writes + v1.x = nil // no barrier + v2.x = nil // ERROR "write barrier" + v1.s = []nih(nil) // no barrier + v2.s = []ih(nil) // ERROR "write barrier" +} + +func g() { + // Test aggregate writes + v1 = t1{x: nil} // no barrier + v2 = t2{x: nil} // ERROR "write barrier" +} + +func h() { + // Test copies and appends. + copy(v1s, v1s[1:]) // no barrier + copy(v2s, v2s[1:]) // ERROR "write barrier" + _ = append(v1s, v1s...) // no barrier + _ = append(v2s, v2s...) // ERROR "write barrier" +} + +// Slice clearing + +var ( + sliceIH []*ih + sliceNIH []*nih +) + +func sliceClear() { + for i := range sliceIH { + sliceIH[i] = nil // ERROR "write barrier" + } + for i := range sliceNIH { + sliceNIH[i] = nil // no barrier + } +} diff --git a/platform/dbops/binaries/go/go/test/import2.dir/import2.go b/platform/dbops/binaries/go/go/test/import2.dir/import2.go new file mode 100644 index 0000000000000000000000000000000000000000..9c54a1b87ea8bb48eaa987c3df75bdd7c42a375a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/import2.dir/import2.go @@ -0,0 +1,42 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Various declarations of exported variables and functions. + +package p + +var C1 chan <- chan int = (chan<- (chan int))(nil) +var C2 chan (<- chan int) = (chan (<-chan int))(nil) +var C3 <- chan chan int = (<-chan (chan int))(nil) +var C4 chan chan <- int = (chan (chan<- int))(nil) + +var C5 <- chan <- chan int = (<-chan (<-chan int))(nil) +var C6 chan <- <- chan int = (chan<- (<-chan int))(nil) +var C7 chan <- chan <- int = (chan<- (chan<- int))(nil) + +var C8 <- chan <- chan chan int = (<-chan (<-chan (chan int)))(nil) +var C9 <- chan chan <- chan int = (<-chan (chan<- (chan int)))(nil) +var C10 chan <- <- chan chan int = (chan<- (<-chan (chan int)))(nil) +var C11 chan <- chan <- chan int = (chan<- (chan<- (chan int)))(nil) +var C12 chan chan <- <- chan int = (chan (chan<- (<-chan int)))(nil) +var C13 chan chan <- chan <- int = (chan (chan<- (chan<- int)))(nil) + +var R1 chan<- (chan int) = (chan <- chan int)(nil) +var R3 <-chan (chan int) = (<- chan chan int)(nil) +var R4 chan (chan<- int) = (chan chan <- int)(nil) + +var R5 <-chan (<-chan int) = (<- chan <- chan int)(nil) +var R6 chan<- (<-chan int) = (chan <- <- chan int)(nil) +var R7 chan<- (chan<- int) = (chan <- chan <- int)(nil) + +var R8 <-chan (<-chan (chan int)) = (<- chan <- chan chan int)(nil) +var R9 <-chan (chan<- (chan int)) = (<- chan chan <- chan int)(nil) +var R10 chan<- (<-chan (chan int)) = (chan <- <- chan chan int)(nil) +var R11 chan<- (chan<- (chan int)) = (chan <- chan <- chan int)(nil) +var R12 chan (chan<- (<-chan int)) = (chan chan <- <- chan int)(nil) +var R13 chan (chan<- (chan<- int)) = (chan chan <- chan <- int)(nil) + +var F1 func() func() int +func F2() func() func() int +func F3(func() func() int) diff --git a/platform/dbops/binaries/go/go/test/import2.dir/import3.go b/platform/dbops/binaries/go/go/test/import2.dir/import3.go new file mode 100644 index 0000000000000000000000000000000000000000..3bf9cb0c3ca356e305e83c9e4799c32faef9ce27 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/import2.dir/import3.go @@ -0,0 +1,52 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that all the types from import2.go made it +// intact and with the same meaning, by assigning to or using them. + +package main + +import "./import2" + +func f3(func() func() int) + +func main() { + p.F3(p.F1) + p.F3(p.F2()) + f3(p.F1) + f3(p.F2()) + + p.C1 = (chan<- (chan int))(nil) + p.C2 = (chan (<-chan int))(nil) + p.C3 = (<-chan (chan int))(nil) + p.C4 = (chan (chan<- int))(nil) + + p.C5 = (<-chan (<-chan int))(nil) + p.C6 = (chan<- (<-chan int))(nil) + p.C7 = (chan<- (chan<- int))(nil) + + p.C8 = (<-chan (<-chan (chan int)))(nil) + p.C9 = (<-chan (chan<- (chan int)))(nil) + p.C10 = (chan<- (<-chan (chan int)))(nil) + p.C11 = (chan<- (chan<- (chan int)))(nil) + p.C12 = (chan (chan<- (<-chan int)))(nil) + p.C13 = (chan (chan<- (chan<- int)))(nil) + + p.R1 = (chan <- chan int)(nil) + p.R3 = (<- chan chan int)(nil) + p.R4 = (chan chan <- int)(nil) + + p.R5 = (<- chan <- chan int)(nil) + p.R6 = (chan <- <- chan int)(nil) + p.R7 = (chan <- chan <- int)(nil) + + p.R8 = (<- chan <- chan chan int)(nil) + p.R9 = (<- chan chan <- chan int)(nil) + p.R10 = (chan <- <- chan chan int)(nil) + p.R11 = (chan <- chan <- chan int)(nil) + p.R12 = (chan chan <- <- chan int)(nil) + p.R13 = (chan chan <- chan <- int)(nil) + +} + diff --git a/platform/dbops/binaries/go/go/test/import4.dir/empty.go b/platform/dbops/binaries/go/go/test/import4.dir/empty.go new file mode 100644 index 0000000000000000000000000000000000000000..1dffa170dfcb6f433c0695285aa5a79bc981be61 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/import4.dir/empty.go @@ -0,0 +1,10 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package empty + +import ( ) +const ( ) +var ( ) +type ( ) diff --git a/platform/dbops/binaries/go/go/test/import4.dir/import4.go b/platform/dbops/binaries/go/go/test/import4.dir/import4.go new file mode 100644 index 0000000000000000000000000000000000000000..dafc5e4b00e61083c52837704b569f271b80126b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/import4.dir/import4.go @@ -0,0 +1,24 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify that various kinds of "imported and not used" +// errors are caught by the compiler. +// Does not compile. + +package main + +// standard +import "fmt" // ERROR "imported and not used.*fmt|\x22fmt\x22 imported and not used" + +// renamed +import X "math" // ERROR "imported and not used.*math|\x22math\x22 imported as X and not used" + +// import dot +import . "bufio" // ERROR "imported and not used.*bufio|imported and not used" + +// again, package without anything in it +import "./empty" // ERROR "imported and not used.*empty|imported and not used" +import Z "./empty" // ERROR "imported and not used.*empty|imported as Z and not used" +import . "./empty" // ERROR "imported and not used.*empty|imported and not used" + diff --git a/platform/dbops/binaries/go/go/test/interface/assertinline.go b/platform/dbops/binaries/go/go/test/interface/assertinline.go new file mode 100644 index 0000000000000000000000000000000000000000..324316b79d4d5428a5022e7dd72c7333aa1e5eb2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/assertinline.go @@ -0,0 +1,74 @@ +// errorcheck -0 -d=typeassert + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func assertptr(x interface{}) *int { + return x.(*int) // ERROR "type assertion inlined" +} + +func assertptr2(x interface{}) (*int, bool) { + z, ok := x.(*int) // ERROR "type assertion inlined" + return z, ok +} + +func assertfunc(x interface{}) func() { + return x.(func()) // ERROR "type assertion inlined" +} + +func assertfunc2(x interface{}) (func(), bool) { + z, ok := x.(func()) // ERROR "type assertion inlined" + return z, ok +} + +func assertstruct(x interface{}) struct{ *int } { + return x.(struct{ *int }) // ERROR "type assertion inlined" +} + +func assertstruct2(x interface{}) (struct{ *int }, bool) { + z, ok := x.(struct{ *int }) // ERROR "type assertion inlined" + return z, ok +} + +func assertbig(x interface{}) complex128 { + return x.(complex128) // ERROR "type assertion inlined" +} + +func assertbig2(x interface{}) (complex128, bool) { + z, ok := x.(complex128) // ERROR "type assertion inlined" + return z, ok +} + +func assertbig2ok(x interface{}) (complex128, bool) { + _, ok := x.(complex128) // ERROR "type assertion inlined" + return 0, ok +} + +func assertslice(x interface{}) []int { + return x.([]int) // ERROR "type assertion inlined" +} + +func assertslice2(x interface{}) ([]int, bool) { + z, ok := x.([]int) // ERROR "type assertion inlined" + return z, ok +} + +func assertslice2ok(x interface{}) ([]int, bool) { + _, ok := x.([]int) // ERROR "type assertion inlined" + return nil, ok +} + +type I interface { + foo() +} + +func assertInter(x interface{}) I { + return x.(I) // ERROR "type assertion not inlined" +} +func assertInter2(x interface{}) (I, bool) { + z, ok := x.(I) // ERROR "type assertion not inlined" + return z, ok +} diff --git a/platform/dbops/binaries/go/go/test/interface/bigdata.go b/platform/dbops/binaries/go/go/test/interface/bigdata.go new file mode 100644 index 0000000000000000000000000000000000000000..0f2e9a990ec9d142b8beddd9b602b90d465d6388 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/bigdata.go @@ -0,0 +1,74 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test big vs. small, pointer vs. value interface methods. + +package main + +type I interface { M() int64 } + +type BigPtr struct { a, b, c, d int64 } +func (z *BigPtr) M() int64 { return z.a+z.b+z.c+z.d } + +type SmallPtr struct { a int32 } +func (z *SmallPtr) M() int64 { return int64(z.a) } + +type IntPtr int32 +func (z *IntPtr) M() int64 { return int64(*z) } + +var bad bool + +func test(name string, i I) { + m := i.M() + if m != 12345 { + println(name, m) + bad = true + } +} + +func ptrs() { + var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 } + var smallptr SmallPtr = SmallPtr{ 12345 } + var intptr IntPtr = 12345 + +// test("bigptr", bigptr) + test("&bigptr", &bigptr) +// test("smallptr", smallptr) + test("&smallptr", &smallptr) +// test("intptr", intptr) + test("&intptr", &intptr) +} + +type Big struct { a, b, c, d int64 } +func (z Big) M() int64 { return z.a+z.b+z.c+z.d } + +type Small struct { a int32 } +func (z Small) M() int64 { return int64(z.a) } + +type Int int32 +func (z Int) M() int64 { return int64(z) } + +func nonptrs() { + var big Big = Big{ 10000, 2000, 300, 45 } + var small Small = Small{ 12345 } + var int Int = 12345 + + test("big", big) + test("&big", &big) + test("small", small) + test("&small", &small) + test("int", int) + test("&int", &int) +} + +func main() { + ptrs() + nonptrs() + + if bad { + println("BUG: interface4") + } +} diff --git a/platform/dbops/binaries/go/go/test/interface/convert.go b/platform/dbops/binaries/go/go/test/interface/convert.go new file mode 100644 index 0000000000000000000000000000000000000000..eb6fd1d5542f206225202a35eedbb6b6a70c9613 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/convert.go @@ -0,0 +1,146 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test all the different interface conversion runtime functions. + +package main + +type Stringer interface { + String() string +} +type StringLengther interface { + String() string + Length() int +} +type Empty interface{} + +type T string + +func (t T) String() string { + return string(t) +} +func (t T) Length() int { + return len(t) +} + +type U string + +func (u U) String() string { + return string(u) +} + +var t = T("hello") +var u = U("goodbye") +var e Empty +var s Stringer = t +var sl StringLengther = t +var i int +var ok bool + +func hello(s string) { + if s != "hello" { + println("not hello: ", s) + panic("fail") + } +} + +func five(i int) { + if i != 5 { + println("not 5: ", i) + panic("fail") + } +} + +func true(ok bool) { + if !ok { + panic("not true") + } +} + +func false(ok bool) { + if ok { + panic("not false") + } +} + +func main() { + // T2I + s = t + hello(s.String()) + + // I2T + t = s.(T) + hello(t.String()) + + // T2E + e = t + + // E2T + t = e.(T) + hello(t.String()) + + // T2I again + sl = t + hello(sl.String()) + five(sl.Length()) + + // I2I static + s = sl + hello(s.String()) + + // I2I dynamic + sl = s.(StringLengther) + hello(sl.String()) + five(sl.Length()) + + // I2E (and E2T) + e = s + hello(e.(T).String()) + + // E2I + s = e.(Stringer) + hello(s.String()) + + // I2T2 true + t, ok = s.(T) + true(ok) + hello(t.String()) + + // I2T2 false + _, ok = s.(U) + false(ok) + + // I2I2 true + sl, ok = s.(StringLengther) + true(ok) + hello(sl.String()) + five(sl.Length()) + + // I2I2 false (and T2I) + s = u + sl, ok = s.(StringLengther) + false(ok) + + // E2T2 true + t, ok = e.(T) + true(ok) + hello(t.String()) + + // E2T2 false + i, ok = e.(int) + false(ok) + + // E2I2 true + sl, ok = e.(StringLengther) + true(ok) + hello(sl.String()) + five(sl.Length()) + + // E2I2 false (and T2E) + e = u + sl, ok = e.(StringLengther) + false(ok) +} diff --git a/platform/dbops/binaries/go/go/test/interface/convert1.go b/platform/dbops/binaries/go/go/test/interface/convert1.go new file mode 100644 index 0000000000000000000000000000000000000000..4a3ec8a375da2f68535fdc48fd0d86abaeff8942 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/convert1.go @@ -0,0 +1,24 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test static interface conversion of interface value nil. + +package main + +type R interface { R() } +type RW interface { R(); W() } + +var e interface {} +var r R +var rw RW + +func main() { + r = r + r = rw + e = r + e = rw + rw = rw +} diff --git a/platform/dbops/binaries/go/go/test/interface/convert2.go b/platform/dbops/binaries/go/go/test/interface/convert2.go new file mode 100644 index 0000000000000000000000000000000000000000..4a3ec8a375da2f68535fdc48fd0d86abaeff8942 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/convert2.go @@ -0,0 +1,24 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test static interface conversion of interface value nil. + +package main + +type R interface { R() } +type RW interface { R(); W() } + +var e interface {} +var r R +var rw RW + +func main() { + r = r + r = rw + e = r + e = rw + rw = rw +} diff --git a/platform/dbops/binaries/go/go/test/interface/embed.go b/platform/dbops/binaries/go/go/test/interface/embed.go new file mode 100644 index 0000000000000000000000000000000000000000..5c52ac0232346651c196e6a4e8fb1321cc8c4940 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/embed.go @@ -0,0 +1,61 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test methods derived from embedded interface values. + +package main + +import "os" + +const Value = 1e12 + +type Inter interface { M() int64 } + +type T int64 +func (t T) M() int64 { return int64(t) } +var t = T(Value) +var pt = &t +var ti Inter = t + +type S struct { Inter } +var s = S{ ti } +var ps = &s + +var i Inter + +var ok = true + +func check(s string, v int64) { + if v != Value { + println(s, v) + ok = false + } +} + +func main() { + check("t.M()", t.M()) + check("pt.M()", pt.M()) + check("ti.M()", ti.M()) + check("s.M()", s.M()) + check("ps.M()", ps.M()) + + i = t + check("i = t; i.M()", i.M()) + + i = pt + check("i = pt; i.M()", i.M()) + + i = s + check("i = s; i.M()", i.M()) + + i = ps + check("i = ps; i.M()", i.M()) + + if !ok { + println("BUG: interface10") + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/interface/embed1.go b/platform/dbops/binaries/go/go/test/interface/embed1.go new file mode 100644 index 0000000000000000000000000000000000000000..784b82bb072b683b9f8caa3390e2b1a154d63aad --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/embed1.go @@ -0,0 +1,9 @@ +// rundir + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that embedded interface types can have local methods. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/interface/embed2.go b/platform/dbops/binaries/go/go/test/interface/embed2.go new file mode 100644 index 0000000000000000000000000000000000000000..97a2d963f04ac717aabea63de11108311eac2f4c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/embed2.go @@ -0,0 +1,75 @@ +// errorcheck + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test methods derived from embedded interface and *interface values. + +package main + +import "os" + +const Value = 1e12 + +type Inter interface { + M() int64 +} + +type T int64 + +func (t T) M() int64 { return int64(t) } + +var t = T(Value) +var pt = &t +var ti Inter = t +var pti = &ti + +type S struct{ Inter } + +var s = S{ti} +var ps = &s + +type SP struct{ *Inter } // ERROR "interface" + +var i Inter +var pi = &i + +var ok = true + +func check(s string, v int64) { + if v != Value { + println(s, v) + ok = false + } +} + +func main() { + check("t.M()", t.M()) + check("pt.M()", pt.M()) + check("ti.M()", ti.M()) + check("pti.M()", pti.M()) // ERROR "pointer to interface, not interface|no field or method M" + check("s.M()", s.M()) + check("ps.M()", ps.M()) + + i = t + check("i = t; i.M()", i.M()) + check("i = t; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" + + i = pt + check("i = pt; i.M()", i.M()) + check("i = pt; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" + + i = s + check("i = s; i.M()", i.M()) + check("i = s; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" + + i = ps + check("i = ps; i.M()", i.M()) + check("i = ps; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" + + if !ok { + println("BUG: interface10") + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/interface/embed3.go b/platform/dbops/binaries/go/go/test/interface/embed3.go new file mode 100644 index 0000000000000000000000000000000000000000..af6f1341729458e04aba9a8a7110ec999540bc2a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/embed3.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/interface/explicit.go b/platform/dbops/binaries/go/go/test/interface/explicit.go new file mode 100644 index 0000000000000000000000000000000000000000..ccdae7873cf66452ebc9271bb5844fead25a5040 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/explicit.go @@ -0,0 +1,106 @@ +// errorcheck + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify compiler messages about erroneous static interface conversions. +// Does not compile. + +package main + +type T struct { + a int +} + +var t *T + +type X int + +func (x *X) M() {} + +type I interface { + M() +} + +var i I + +type I2 interface { + M() + N() +} + +var i2 I2 + +type E interface{} + +var e E + +func main() { + e = t // ok + t = e // ERROR "need explicit|need type assertion" + + // neither of these can work, + // because i has an extra method + // that t does not, so i cannot contain a t. + i = t // ERROR "incompatible|missing method M" + t = i // ERROR "incompatible|assignment$" + + i = i2 // ok + i2 = i // ERROR "incompatible|missing method N" + + i = I(i2) // ok + i2 = I2(i) // ERROR "invalid|missing N method|cannot convert" + + e = E(t) // ok + t = T(e) // ERROR "need explicit|need type assertion|incompatible|cannot convert" + + // cannot type-assert non-interfaces + f := 2.0 + _ = f.(int) // ERROR "non-interface type|only valid for interface types|not an interface" + +} + +type M interface { + M() +} + +var m M + +var _ = m.(int) // ERROR "impossible type assertion" + +type Int int + +func (Int) M(float64) {} + +var _ = m.(Int) // ERROR "impossible type assertion" + +var _ = m.(X) // ERROR "pointer receiver" + +var ii int +var jj Int + +var m1 M = ii // ERROR "incompatible|missing" +var m2 M = jj // ERROR "incompatible|wrong type for method M" + +var m3 = M(ii) // ERROR "invalid|missing|cannot convert" +var m4 = M(jj) // ERROR "invalid|wrong type for M method|cannot convert" + +type B1 interface { + _() // ERROR "methods must have a unique non-blank name" +} + +type B2 interface { + M() + _() // ERROR "methods must have a unique non-blank name" +} + +type T2 struct{} + +func (t *T2) M() {} +func (t *T2) _() {} + +// Already reported about the invalid blank interface method above; +// no need to report about not implementing it. +var b1 B1 = &T2{} +var b2 B2 = &T2{} diff --git a/platform/dbops/binaries/go/go/test/interface/fail.go b/platform/dbops/binaries/go/go/test/interface/fail.go new file mode 100644 index 0000000000000000000000000000000000000000..d40a1513832115bc8c3d015575126d14141f564d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/fail.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that interface conversion fails when method is missing. + +package main + +type I interface { + Foo() +} + +func main() { + shouldPanic(p1) +} + +func p1() { + var s *S + var i I + var e interface{} + e = s + i = e.(I) + _ = i +} + +type S struct{} + +func (s *S) _() {} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/platform/dbops/binaries/go/go/test/interface/fake.go b/platform/dbops/binaries/go/go/test/interface/fake.go new file mode 100644 index 0000000000000000000000000000000000000000..861a640842f6400f62ca2eea88a2ee401f6fefa9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/fake.go @@ -0,0 +1,97 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interface comparisons using types hidden +// inside reflected-on structs. + +package main + +import "reflect" + +type T struct { + F float32 + G float32 + + S string + T string + + U uint32 + V uint32 + + W uint32 + X uint32 + + Y uint32 + Z uint32 +} + +func add(s, t string) string { + return s + t +} + +func assert(b bool) { + if !b { + panic("assert") + } +} + +func main() { + var x T + x.F = 1.0 + x.G = x.F + x.S = add("abc", "def") + x.T = add("abc", "def") + x.U = 1 + x.V = 2 + x.W = 1 << 28 + x.X = 2 << 28 + x.Y = 0x12345678 + x.Z = x.Y + + // check mem and string + v := reflect.ValueOf(x) + i := v.Field(0) + j := v.Field(1) + assert(i.Interface() == j.Interface()) + + s := v.Field(2) + t := v.Field(3) + assert(s.Interface() == t.Interface()) + + // make sure different values are different. + // make sure whole word is being compared, + // not just a single byte. + i = v.Field(4) + j = v.Field(5) + assert(i.Interface() != j.Interface()) + + i = v.Field(6) + j = v.Field(7) + assert(i.Interface() != j.Interface()) + + i = v.Field(8) + j = v.Field(9) + assert(i.Interface() == j.Interface()) +} + +/* +comparing uncomparable type float32 +throw: interface compare + +panic PC=0x28ceb8 [1] +throw+0x41 /Users/rsc/goX/src/runtime/runtime.c:54 + throw(0x3014a, 0x0) +ifaceeq+0x15c /Users/rsc/goX/src/runtime/iface.c:501 + ifaceeq(0x2aa7c0, 0x0, 0x0, 0x0, 0x2aa7c0, ...) +sys·ifaceeq+0x48 /Users/rsc/goX/src/runtime/iface.c:527 + sys·ifaceeq(0x2aa7c0, 0x0, 0x0, 0x0, 0x2aa7c0, ...) +main·main+0x190 /Users/rsc/goX/src/cmd/gc/x.go:10 + main·main() +mainstart+0xf /Users/rsc/goX/src/runtime/amd64/asm.s:53 + mainstart() +sys·Goexit /Users/rsc/goX/src/runtime/proc.c:124 + sys·Goexit() +*/ diff --git a/platform/dbops/binaries/go/go/test/interface/noeq.go b/platform/dbops/binaries/go/go/test/interface/noeq.go new file mode 100644 index 0000000000000000000000000000000000000000..bb36893cd0d991893284689224f5310fb207391c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/noeq.go @@ -0,0 +1,40 @@ +// run + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test run-time error detection for interface values containing types +// that cannot be compared for equality. + +package main + +func main() { + cmp(1) + + var ( + m map[int]int + s struct{ x []int } + f func() + ) + noCmp(m) + noCmp(s) + noCmp(f) +} + +func cmp(x interface{}) bool { + return x == x +} + +func noCmp(x interface{}) { + shouldPanic(func() { cmp(x) }) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/platform/dbops/binaries/go/go/test/interface/pointer.go b/platform/dbops/binaries/go/go/test/interface/pointer.go new file mode 100644 index 0000000000000000000000000000000000000000..c9651d2ce6d86b3f793029c6af37358650cc0871 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/pointer.go @@ -0,0 +1,37 @@ +// errorcheck + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that interface{M()} = *interface{M()} produces a compiler error. +// Does not compile. + +package main + +type Inst interface { + Next() *Inst +} + +type Regexp struct { + code []Inst + start Inst +} + +type Start struct { + foo *Inst +} + +func (start *Start) Next() *Inst { return nil } + +func AddInst(Inst) *Inst { + print("ok in addinst\n") + return nil +} + +func main() { + print("call addinst\n") + var _ Inst = AddInst(new(Start)) // ERROR "pointer to interface|incompatible type" + print("return from addinst\n") + var _ *Inst = new(Start) // ERROR "pointer to interface|incompatible type" +} diff --git a/platform/dbops/binaries/go/go/test/interface/private.go b/platform/dbops/binaries/go/go/test/interface/private.go new file mode 100644 index 0000000000000000000000000000000000000000..a0da249c92c505801ed250f252a13e7180f4b940 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/private.go @@ -0,0 +1,10 @@ +// errorcheckdir + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that unexported methods are not visible outside the package. +// Does not compile. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/interface/receiver.go b/platform/dbops/binaries/go/go/test/interface/receiver.go new file mode 100644 index 0000000000000000000000000000000000000000..4511ab3b473c1e11786e2a59b4b43f72f56ba1c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/receiver.go @@ -0,0 +1,121 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test Implicit methods for embedded types and +// mixed pointer and non-pointer receivers. + +package main + +type T int + +var nv, np int + +func (t T) V() { + if t != 42 { + panic(t) + } + nv++ +} + +func (t *T) P() { + if *t != 42 { + println(t, *t) + panic("fail") + } + np++ +} + +type V interface { + V() +} +type P interface { + P() + V() +} + +type S struct { + T +} + +type SP struct { + *T +} + +func main() { + var t T + var v V + var p P + + t = 42 + + t.P() + t.V() + + v = t + v.V() + + p = &t + p.P() + p.V() + + v = &t + v.V() + + // p = t // ERROR + var i interface{} = t + if _, ok := i.(P); ok { + println("dynamic i.(P) succeeded incorrectly") + panic("fail") + } + + // println("--struct--"); + var s S + s.T = 42 + s.P() + s.V() + + v = s + s.V() + + p = &s + p.P() + p.V() + + v = &s + v.V() + + // p = s // ERROR + var j interface{} = s + if _, ok := j.(P); ok { + println("dynamic j.(P) succeeded incorrectly") + panic("fail") + } + + // println("--struct pointer--"); + var sp SP + sp.T = &t + sp.P() + sp.V() + + v = sp + sp.V() + + p = &sp + p.P() + p.V() + + v = &sp + v.V() + + p = sp // not error + p.P() + p.V() + + if nv != 13 || np != 7 { + println("bad count", nv, np) + panic("fail") + } +} diff --git a/platform/dbops/binaries/go/go/test/interface/receiver1.go b/platform/dbops/binaries/go/go/test/interface/receiver1.go new file mode 100644 index 0000000000000000000000000000000000000000..a0a87534a4a472e8643a9c6d0c8724f0e38fea09 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/receiver1.go @@ -0,0 +1,59 @@ +// errorcheck + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify compiler complains about missing implicit methods. +// Does not compile. + +package main + +type T int + +func (t T) V() +func (t *T) P() + +type V interface { + V() +} +type P interface { + P() + V() +} + +type S struct { + T +} +type SP struct { + *T +} + +func main() { + var t T + var v V + var p P + var s S + var sp SP + + v = t + p = t // ERROR "does not implement|requires a pointer|cannot use" + _, _ = v, p + v = &t + p = &t + _, _ = v, p + + v = s + p = s // ERROR "does not implement|requires a pointer|cannot use" + _, _ = v, p + v = &s + p = &s + _, _ = v, p + + v = sp + p = sp // no error! + _, _ = v, p + v = &sp + p = &sp + _, _ = v, p +} diff --git a/platform/dbops/binaries/go/go/test/interface/recursive.go b/platform/dbops/binaries/go/go/test/interface/recursive.go new file mode 100644 index 0000000000000000000000000000000000000000..fcc88331e0b3e61e68ec55b5546899d3ae23c920 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/recursive.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check mutually recursive interfaces + +package recursive + +type I1 interface { + foo() I2 +} + +type I2 interface { + bar() I1 +} + +type T int +func (t T) foo() I2 { return t } +func (t T) bar() I1 { return t } diff --git a/platform/dbops/binaries/go/go/test/interface/recursive1.go b/platform/dbops/binaries/go/go/test/interface/recursive1.go new file mode 100644 index 0000000000000000000000000000000000000000..ea2f4eb934a66a77e94c03f054ff3a54aac6bc26 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/recursive1.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Mutually recursive type definitions imported and used by recursive1.go. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/interface/returntype.go b/platform/dbops/binaries/go/go/test/interface/returntype.go new file mode 100644 index 0000000000000000000000000000000000000000..4d86f39184090727a471f5881851d32f760310c4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/returntype.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interface methods with different return types are distinct. + +package main + +type S struct { a int } +type T struct { b string } + +func (s *S) Name() int8 { return 1 } +func (t *T) Name() int64 { return 64 } + +type I1 interface { Name() int8 } +type I2 interface { Name() int64 } + +func main() { + shouldPanic(p1) +} + +func p1() { + var i1 I1 + var s *S + i1 = s + print(i1.(I2).Name()) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/platform/dbops/binaries/go/go/test/interface/struct.go b/platform/dbops/binaries/go/go/test/interface/struct.go new file mode 100644 index 0000000000000000000000000000000000000000..f60819ca8116f24c77132cc8a3cb6676ff76b922 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/interface/struct.go @@ -0,0 +1,156 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interface values containing structures. + +package main + +import "os" + +var fail int + +func check(b bool, msg string) { + if (!b) { + println("failure in", msg) + fail++ + } +} + +type I1 interface { Get() int; Put(int) } + +type S1 struct { i int } +func (p S1) Get() int { return p.i } +func (p S1) Put(i int) { p.i = i } + +func f1() { + s := S1{1} + var i I1 = s + i.Put(2) + check(i.Get() == 1, "f1 i") + check(s.i == 1, "f1 s") +} + +func f2() { + s := S1{1} + var i I1 = &s + i.Put(2) + check(i.Get() == 1, "f2 i") + check(s.i == 1, "f2 s") +} + +func f3() { + s := &S1{1} + var i I1 = s + i.Put(2) + check(i.Get() == 1, "f3 i") + check(s.i == 1, "f3 s") +} + +type S2 struct { i int } +func (p *S2) Get() int { return p.i } +func (p *S2) Put(i int) { p.i = i } + +// Disallowed by restriction of values going to pointer receivers +// func f4() { +// s := S2{1} +// var i I1 = s +// i.Put(2) +// check(i.Get() == 2, "f4 i") +// check(s.i == 1, "f4 s") +// } + +func f5() { + s := S2{1} + var i I1 = &s + i.Put(2) + check(i.Get() == 2, "f5 i") + check(s.i == 2, "f5 s") +} + +func f6() { + s := &S2{1} + var i I1 = s + i.Put(2) + check(i.Get() == 2, "f6 i") + check(s.i == 2, "f6 s") +} + +type I2 interface { Get() int64; Put(int64) } + +type S3 struct { i, j, k, l int64 } +func (p S3) Get() int64 { return p.l } +func (p S3) Put(i int64) { p.l = i } + +func f7() { + s := S3{1, 2, 3, 4} + var i I2 = s + i.Put(5) + check(i.Get() == 4, "f7 i") + check(s.l == 4, "f7 s") +} + +func f8() { + s := S3{1, 2, 3, 4} + var i I2 = &s + i.Put(5) + check(i.Get() == 4, "f8 i") + check(s.l == 4, "f8 s") +} + +func f9() { + s := &S3{1, 2, 3, 4} + var i I2 = s + i.Put(5) + check(i.Get() == 4, "f9 i") + check(s.l == 4, "f9 s") +} + +type S4 struct { i, j, k, l int64 } +func (p *S4) Get() int64 { return p.l } +func (p *S4) Put(i int64) { p.l = i } + +// Disallowed by restriction of values going to pointer receivers +// func f10() { +// s := S4{1, 2, 3, 4} +// var i I2 = s +// i.Put(5) +// check(i.Get() == 5, "f10 i") +// check(s.l == 4, "f10 s") +// } + +func f11() { + s := S4{1, 2, 3, 4} + var i I2 = &s + i.Put(5) + check(i.Get() == 5, "f11 i") + check(s.l == 5, "f11 s") +} + +func f12() { + s := &S4{1, 2, 3, 4} + var i I2 = s + i.Put(5) + check(i.Get() == 5, "f12 i") + check(s.l == 5, "f12 s") +} + +func main() { + f1() + f2() + f3() +// f4() + f5() + f6() + f7() + f8() + f9() +// f10() + f11() + f12() + if fail > 0 { + os.Exit(1) + } +} diff --git a/platform/dbops/binaries/go/go/test/intrinsic.dir/main.go b/platform/dbops/binaries/go/go/test/intrinsic.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..951aa159d6709a2c9a6453ff90c9e858fcf858c6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/intrinsic.dir/main.go @@ -0,0 +1,94 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + T "runtime/internal/sys" +) + +var A = []uint64{0x0102030405060708, 0x1122334455667788} +var B = []uint64{0x0807060504030201, 0x8877665544332211} + +var errors int + +func logf(f string, args ...interface{}) { + errors++ + fmt.Printf(f, args...) + if errors > 100 { // 100 is enough spewage + panic("100 errors is plenty is enough") + } +} + +func test(i int, x uint64) { + t := T.TrailingZeros64(x) // ERROR "intrinsic substitution for TrailingZeros64" + if i != t { + logf("TrailingZeros64(0x%x) expected %d but got %d\n", x, i, t) + } + x = -x + t = T.TrailingZeros64(x) // ERROR "intrinsic substitution for TrailingZeros64" + if i != t { + logf("TrailingZeros64(0x%x) expected %d but got %d\n", x, i, t) + } + + if i <= 32 { + x32 := uint32(x) + t32 := T.TrailingZeros32(x32) // ERROR "intrinsic substitution for TrailingZeros32" + if i != t32 { + logf("TrailingZeros32(0x%x) expected %d but got %d\n", x32, i, t32) + } + x32 = -x32 + t32 = T.TrailingZeros32(x32) // ERROR "intrinsic substitution for TrailingZeros32" + if i != t32 { + logf("TrailingZeros32(0x%x) expected %d but got %d\n", x32, i, t32) + } + } +} + +func main() { + // Test Bswap first because the other test relies on it + // working correctly (to implement bit reversal). + for i := range A { + x := A[i] + y := B[i] + X := T.Bswap64(x) // ERROR "intrinsic substitution for Bswap64" + Y := T.Bswap64(y) // ERROR "intrinsic substitution for Bswap64" + if y != X { + logf("Bswap64(0x%08x) expected 0x%08x but got 0x%08x\n", x, y, X) + } + if x != Y { + logf("Bswap64(0x%08x) expected 0x%08x but got 0x%08x\n", y, x, Y) + } + + x32 := uint32(X) + y32 := uint32(Y >> 32) + + X32 := T.Bswap32(x32) // ERROR "intrinsic substitution for Bswap32" + Y32 := T.Bswap32(y32) // ERROR "intrinsic substitution for Bswap32" + if y32 != X32 { + logf("Bswap32(0x%08x) expected 0x%08x but got 0x%08x\n", x32, y32, X32) + } + if x32 != Y32 { + logf("Bswap32(0x%08x) expected 0x%08x but got 0x%08x\n", y32, x32, Y32) + } + } + + // Zero is a special case, be sure it is done right. + if T.TrailingZeros32(0) != 32 { // ERROR "intrinsic substitution for TrailingZeros32" + logf("TrailingZeros32(0) != 32") + } + if T.TrailingZeros64(0) != 64 { // ERROR "intrinsic substitution for TrailingZeros64" + logf("TrailingZeros64(0) != 64") + } + + for i := 0; i <= 64; i++ { + for j := uint64(1); j <= 255; j += 2 { + for k := uint64(1); k <= 65537; k += 128 { + x := (j * k) << uint(i) + test(i, x) + } + } + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/array.go b/platform/dbops/binaries/go/go/test/ken/array.go new file mode 100644 index 0000000000000000000000000000000000000000..9412e3502dd950a12919dfedde52d797e824ed0a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/array.go @@ -0,0 +1,138 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test arrays and slices. + +package main + +func setpd(a []int) { + // print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i + } +} + +func sumpd(a []int) int { + // print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] + } + // print("sumpd t=", t, "\n"); + return t +} + +func setpf(a *[20]int) { + // print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i + } +} + +func sumpf(a *[20]int) int { + // print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] + } + // print("sumpf t=", t, "\n"); + return t +} + +func res(t int, lb, hb int) { + sb := (hb - lb) * (hb + lb - 1) / 2 + if t != sb { + print("lb=", lb, + "; hb=", hb, + "; t=", t, + "; sb=", sb, + "\n") + panic("res") + } +} + +// call ptr dynamic with ptr dynamic +func testpdpd() { + a := make([]int, 10, 100) + if len(a) != 10 && cap(a) != 100 { + print("len and cap from new: ", len(a), " ", cap(a), "\n") + panic("fail") + } + + a = a[0:100] + setpd(a) + + a = a[0:10] + res(sumpd(a), 0, 10) + + a = a[5:25] + res(sumpd(a), 5, 25) + + a = a[30:95] + res(sumpd(a), 35, 100) +} + +// call ptr fixed with ptr fixed +func testpfpf() { + var a [20]int + + setpf(&a) + res(sumpf(&a), 0, 20) +} + +// call ptr dynamic with ptr fixed from new +func testpdpf1() { + a := new([40]int) + setpd(a[0:]) + res(sumpd(a[0:]), 0, 40) + + b := (*a)[5:30] + res(sumpd(b), 5, 30) +} + +// call ptr dynamic with ptr fixed from var +func testpdpf2() { + var a [80]int + + setpd(a[0:]) + res(sumpd(a[0:]), 0, 80) +} + +// generate bounds error with ptr dynamic +func testpdfault() { + a := make([]int, 100) + + print("good\n") + for i := 0; i < 100; i++ { + a[i] = 0 + } + print("should fault\n") + a[100] = 0 + print("bad\n") +} + +// generate bounds error with ptr fixed +func testfdfault() { + var a [80]int + + print("good\n") + for i := 0; i < 80; i++ { + a[i] = 0 + } + print("should fault\n") + x := 80 + a[x] = 0 + print("bad\n") +} + +func main() { + testpdpd() + testpfpf() + testpdpf1() + testpdpf2() + // print("testpdfault\n"); testpdfault(); + // print("testfdfault\n"); testfdfault(); +} diff --git a/platform/dbops/binaries/go/go/test/ken/chan.go b/platform/dbops/binaries/go/go/test/ken/chan.go new file mode 100644 index 0000000000000000000000000000000000000000..36b18f80ea9faf66423a310d81d8d9bb6f9337a2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/chan.go @@ -0,0 +1,331 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test communication operations including select. + +package main + +import "os" +import "runtime" +import "sync" + +var randx int + +func nrand(n int) int { + randx += 10007 + if randx >= 1000000 { + randx -= 1000000 + } + return randx % n +} + +type Chan struct { + sc, rc chan int // send and recv chan + sv, rv int // send and recv seq +} + +var ( + nproc int + nprocLock sync.Mutex + cval int + end int = 10000 + totr, tots int + totLock sync.Mutex + nc *Chan +) + +func init() { + nc = new(Chan) +} + +func changeNproc(adjust int) int { + nprocLock.Lock() + nproc += adjust + ret := nproc + nprocLock.Unlock() + return ret +} + +func mkchan(c, n int) []*Chan { + ca := make([]*Chan, n) + for i := 0; i < n; i++ { + cval = cval + 100 + ch := new(Chan) + ch.sc = make(chan int, c) + ch.rc = ch.sc + ch.sv = cval + ch.rv = cval + ca[i] = ch + } + return ca +} + +func expect(v, v0 int) (newv int) { + if v == v0 { + if v%100 == 75 { + return end + } + return v + 1 + } + print("got ", v, " expected ", v0+1, "\n") + panic("fail") +} + +func (c *Chan) send() bool { + // print("send ", c.sv, "\n"); + totLock.Lock() + tots++ + totLock.Unlock() + c.sv = expect(c.sv, c.sv) + if c.sv == end { + c.sc = nil + return true + } + return false +} + +func send(c *Chan) { + for { + for r := nrand(10); r >= 0; r-- { + runtime.Gosched() + } + c.sc <- c.sv + if c.send() { + break + } + } + changeNproc(-1) +} + +func (c *Chan) recv(v int) bool { + // print("recv ", v, "\n"); + totLock.Lock() + totr++ + totLock.Unlock() + c.rv = expect(c.rv, v) + if c.rv == end { + c.rc = nil + return true + } + return false +} + +func recv(c *Chan) { + var v int + + for { + for r := nrand(10); r >= 0; r-- { + runtime.Gosched() + } + v = <-c.rc + if c.recv(v) { + break + } + } + changeNproc(-1) +} + +func sel(r0, r1, r2, r3, s0, s1, s2, s3 *Chan) { + var v int + + a := 0 // local chans running + + if r0.rc != nil { + a++ + } + if r1.rc != nil { + a++ + } + if r2.rc != nil { + a++ + } + if r3.rc != nil { + a++ + } + if s0.sc != nil { + a++ + } + if s1.sc != nil { + a++ + } + if s2.sc != nil { + a++ + } + if s3.sc != nil { + a++ + } + + for { + for r := nrand(5); r >= 0; r-- { + runtime.Gosched() + } + + select { + case v = <-r0.rc: + if r0.recv(v) { + a-- + } + case v = <-r1.rc: + if r1.recv(v) { + a-- + } + case v = <-r2.rc: + if r2.recv(v) { + a-- + } + case v = <-r3.rc: + if r3.recv(v) { + a-- + } + case s0.sc <- s0.sv: + if s0.send() { + a-- + } + case s1.sc <- s1.sv: + if s1.send() { + a-- + } + case s2.sc <- s2.sv: + if s2.send() { + a-- + } + case s3.sc <- s3.sv: + if s3.send() { + a-- + } + } + if a == 0 { + break + } + } + changeNproc(-1) +} + +// direct send to direct recv +func test1(c *Chan) { + changeNproc(2) + go send(c) + go recv(c) +} + +// direct send to select recv +func test2(c int) { + ca := mkchan(c, 4) + + changeNproc(4) + go send(ca[0]) + go send(ca[1]) + go send(ca[2]) + go send(ca[3]) + + changeNproc(1) + go sel(ca[0], ca[1], ca[2], ca[3], nc, nc, nc, nc) +} + +// select send to direct recv +func test3(c int) { + ca := mkchan(c, 4) + + changeNproc(4) + go recv(ca[0]) + go recv(ca[1]) + go recv(ca[2]) + go recv(ca[3]) + + changeNproc(1) + go sel(nc, nc, nc, nc, ca[0], ca[1], ca[2], ca[3]) +} + +// select send to select recv +func test4(c int) { + ca := mkchan(c, 4) + + changeNproc(2) + go sel(nc, nc, nc, nc, ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], nc, nc, nc, nc) +} + +func test5(c int) { + ca := mkchan(c, 8) + + changeNproc(2) + go sel(ca[4], ca[5], ca[6], ca[7], ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], ca[4], ca[5], ca[6], ca[7]) +} + +func test6(c int) { + ca := mkchan(c, 12) + + changeNproc(4) + go send(ca[4]) + go send(ca[5]) + go send(ca[6]) + go send(ca[7]) + + changeNproc(4) + go recv(ca[8]) + go recv(ca[9]) + go recv(ca[10]) + go recv(ca[11]) + + changeNproc(2) + go sel(ca[4], ca[5], ca[6], ca[7], ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], ca[8], ca[9], ca[10], ca[11]) +} + +// wait for outstanding tests to finish +func wait() { + runtime.Gosched() + for changeNproc(0) != 0 { + runtime.Gosched() + } +} + +// run all tests with specified buffer size +func tests(c int) { + ca := mkchan(c, 4) + test1(ca[0]) + test1(ca[1]) + test1(ca[2]) + test1(ca[3]) + wait() + + test2(c) + wait() + + test3(c) + wait() + + test4(c) + wait() + + test5(c) + wait() + + test6(c) + wait() +} + +// run all test with 4 buffser sizes +func main() { + + tests(0) + tests(1) + tests(10) + tests(100) + + t := 4 * // buffer sizes + (4*4 + // tests 1,2,3,4 channels + 8 + // test 5 channels + 12) * // test 6 channels + 76 // sends/recvs on a channel + + if tots != t || totr != t { + print("tots=", tots, " totr=", totr, " sb=", t, "\n") + os.Exit(1) + } + os.Exit(0) +} diff --git a/platform/dbops/binaries/go/go/test/ken/chan1.go b/platform/dbops/binaries/go/go/test/ken/chan1.go new file mode 100644 index 0000000000000000000000000000000000000000..cbd21a3d69c074d53b97a655e22e3afd5bdf7847 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/chan1.go @@ -0,0 +1,55 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test communication with multiple simultaneous goroutines. + +package main + +import "runtime" + +const N = 1000 // sent messages +const M = 10 // receiving goroutines +const W = 2 // channel buffering +var h [N]int // marking of send/recv + +func r(c chan int, m int) { + for { + select { + case r := <-c: + if h[r] != 1 { + println("r", + "m=", m, + "r=", r, + "h=", h[r]) + panic("fail") + } + h[r] = 2 + } + } +} + +func s(c chan int) { + for n := 0; n < N; n++ { + r := n + if h[r] != 0 { + println("s") + panic("fail") + } + h[r] = 1 + c <- r + } +} + +func main() { + c := make(chan int, W) + for m := 0; m < M; m++ { + go r(c, m) + runtime.Gosched() + } + runtime.Gosched() + runtime.Gosched() + s(c) +} diff --git a/platform/dbops/binaries/go/go/test/ken/complit.go b/platform/dbops/binaries/go/go/test/ken/complit.go new file mode 100644 index 0000000000000000000000000000000000000000..bc50bbe224c35278289513bfed53d2018e0496a4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/complit.go @@ -0,0 +1,172 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test composite literals. + +package main + +type M map[int]int +type S struct{ a,b,c int }; +type SS struct{ aa,bb,cc S }; +type SA struct{ a,b,c [3]int }; +type SC struct{ a,b,c []int }; +type SM struct{ a,b,c M }; + +func +main() { + test("s.a", s.a); + test("s.b", s.b); + test("s.c", s.c); + + test("ss.aa.a", ss.aa.a); + test("ss.aa.b", ss.aa.b); + test("ss.aa.c", ss.aa.c); + + test("ss.bb.a", ss.bb.a); + test("ss.bb.b", ss.bb.b); + test("ss.bb.c", ss.bb.c); + + test("ss.cc.a", ss.cc.a); + test("ss.cc.b", ss.cc.b); + test("ss.cc.c", ss.cc.c); + + for i:=0; i<3; i++ { + test("a[i]", a[i]); + test("c[i]", c[i]); + test("m[i]", m[i]); + + test("as[i].a", as[i].a); + test("as[i].b", as[i].b); + test("as[i].c", as[i].c); + + test("cs[i].a", cs[i].a); + test("cs[i].b", cs[i].b); + test("cs[i].c", cs[i].c); + + test("ms[i].a", ms[i].a); + test("ms[i].b", ms[i].b); + test("ms[i].c", ms[i].c); + + test("sa.a[i]", sa.a[i]); + test("sa.b[i]", sa.b[i]); + test("sa.c[i]", sa.c[i]); + + test("sc.a[i]", sc.a[i]); + test("sc.b[i]", sc.b[i]); + test("sc.c[i]", sc.c[i]); + + test("sm.a[i]", sm.a[i]); + test("sm.b[i]", sm.b[i]); + test("sm.c[i]", sm.c[i]); + + for j:=0; j<3; j++ { + test("aa[i][j]", aa[i][j]); + test("ac[i][j]", ac[i][j]); + test("am[i][j]", am[i][j]); + test("ca[i][j]", ca[i][j]); + test("cc[i][j]", cc[i][j]); + test("cm[i][j]", cm[i][j]); + test("ma[i][j]", ma[i][j]); + test("mc[i][j]", mc[i][j]); + test("mm[i][j]", mm[i][j]); + } + } + +} + +var ref = 0; + +func +test(xs string, x int) { + + if ref >= len(answers) { + println(xs, x); + return; + } + + if x != answers[ref] { + println(xs, "is", x, "should be", answers[ref]) + } + ref++; +} + + +var a = [3]int{1001, 1002, 1003} +var s = S{1101, 1102, 1103} +var c = []int{1201, 1202, 1203} +var m = M{0:1301, 1:1302, 2:1303} + +var aa = [3][3]int{[3]int{2001,2002,2003}, [3]int{2004,2005,2006}, [3]int{2007,2008,2009}} +var as = [3]S{S{2101,2102,2103},S{2104,2105,2106},S{2107,2108,2109}} +var ac = [3][]int{[]int{2201,2202,2203}, []int{2204,2205,2206}, []int{2207,2208,2209}} +var am = [3]M{M{0:2301,1:2302,2:2303}, M{0:2304,1:2305,2:2306}, M{0:2307,1:2308,2:2309}} + +var sa = SA{[3]int{3001,3002,3003},[3]int{3004,3005,3006},[3]int{3007,3008,3009}} +var ss = SS{S{3101,3102,3103},S{3104,3105,3106},S{3107,3108,3109}} +var sc = SC{[]int{3201,3202,3203},[]int{3204,3205,3206},[]int{3207,3208,3209}} +var sm = SM{M{0:3301,1:3302,2:3303}, M{0:3304,1:3305,2:3306}, M{0:3307,1:3308,2:3309}} + +var ca = [][3]int{[3]int{4001,4002,4003}, [3]int{4004,4005,4006}, [3]int{4007,4008,4009}} +var cs = []S{S{4101,4102,4103},S{4104,4105,4106},S{4107,4108,4109}} +var cc = [][]int{[]int{4201,4202,4203}, []int{4204,4205,4206}, []int{4207,4208,4209}} +var cm = []M{M{0:4301,1:4302,2:4303}, M{0:4304,1:4305,2:4306}, M{0:4307,1:4308,2:4309}} + +var ma = map[int][3]int{0:[3]int{5001,5002,5003}, 1:[3]int{5004,5005,5006}, 2:[3]int{5007,5008,5009}} +var ms = map[int]S{0:S{5101,5102,5103},1:S{5104,5105,5106},2:S{5107,5108,5109}} +var mc = map[int][]int{0:[]int{5201,5202,5203}, 1:[]int{5204,5205,5206}, 2:[]int{5207,5208,5209}} +var mm = map[int]M{0:M{0:5301,1:5302,2:5303}, 1:M{0:5304,1:5305,2:5306}, 2:M{0:5307,1:5308,2:5309}} + +var answers = [...]int { + // s + 1101, 1102, 1103, + + // ss + 3101, 3102, 3103, + 3104, 3105, 3106, + 3107, 3108, 3109, + + // [0] + 1001, 1201, 1301, + 2101, 2102, 2103, + 4101, 4102, 4103, + 5101, 5102, 5103, + 3001, 3004, 3007, + 3201, 3204, 3207, + 3301, 3304, 3307, + + // [0][j] + 2001, 2201, 2301, 4001, 4201, 4301, 5001, 5201, 5301, + 2002, 2202, 2302, 4002, 4202, 4302, 5002, 5202, 5302, + 2003, 2203, 2303, 4003, 4203, 4303, 5003, 5203, 5303, + + // [1] + 1002, 1202, 1302, + 2104, 2105, 2106, + 4104, 4105, 4106, + 5104, 5105, 5106, + 3002, 3005, 3008, + 3202, 3205, 3208, + 3302, 3305, 3308, + + // [1][j] + 2004, 2204, 2304, 4004, 4204, 4304, 5004, 5204, 5304, + 2005, 2205, 2305, 4005, 4205, 4305, 5005, 5205, 5305, + 2006, 2206, 2306, 4006, 4206, 4306, 5006, 5206, 5306, + + // [2] + 1003, 1203, 1303, + 2107, 2108, 2109, + 4107, 4108, 4109, + 5107, 5108, 5109, + 3003, 3006, 3009, + 3203, 3206, 3209, + 3303, 3306, 3309, + + // [2][j] + 2007, 2207, 2307, 4007, 4207, 4307, 5007, 5207, 5307, + 2008, 2208, 2308, 4008, 4208, 4308, 5008, 5208, 5308, + 2009, 2209, 2309, 4009, 4209, 4309, 5009, 5209, 5309, +} diff --git a/platform/dbops/binaries/go/go/test/ken/convert.go b/platform/dbops/binaries/go/go/test/ken/convert.go new file mode 100644 index 0000000000000000000000000000000000000000..33acbd8cd2184f70bab6a6b2c7d4aeac74520132 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/convert.go @@ -0,0 +1,432 @@ +// run + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test, near-exhaustive, of converting numbers between types. +// No complex numbers though. + +package main + +var i8 int8; +var u8 uint8; +var i16 int16; +var u16 uint16; +var i32 int32; +var u32 uint32; +var i64 int64; +var u64 uint64; +var f32 float32; +var f64 float64; + +type big float64 + +type t struct { + from, to int + val big +} + +const ( + ti8 = iota+1 + tu8 + ti16 + tu16 + ti32 + tu32 + ti64 + tu64 + tf32 + tf64 +) + +var x = []t{ + + /* value good in all types (10) */ + { ti8, ti8, 10 }, { ti8, tu8, 10 }, { ti8, ti16, 10 }, { ti8, tu16, 10 }, + { ti8, ti32, 10 }, { ti8, tu32, 10 }, { ti8, ti64, 10 }, { ti8, tu64, 10 }, + { ti8, tf32, 10 }, { ti8, tf64, 10 }, + + { tu8, ti8, 10 }, { tu8, tu8, 10 }, { tu8, ti16, 10 }, { tu8, tu16, 10 }, + { tu8, ti32, 10 }, { tu8, tu32, 10 }, { tu8, ti64, 10 }, { tu8, tu64, 10 }, + { tu8, tf32, 10 }, { tu8, tf64, 10 }, + + { ti16, ti8, 10 }, { ti16, tu8, 10 }, { ti16, ti16, 10 }, { ti16, tu16, 10 }, + { ti16, ti32, 10 }, { ti16, tu32, 10 }, { ti16, ti64, 10 }, { ti16, tu64, 10 }, + { ti16, tf32, 10 }, { ti16, tf64, 10 }, + + { tu16, ti8, 10 }, { tu16, tu8, 10 }, { tu16, ti16, 10 }, { tu16, tu16, 10 }, + { tu16, ti32, 10 }, { tu16, tu32, 10 }, { tu16, ti64, 10 }, { tu16, tu64, 10 }, + { tu16, tf32, 10 }, { tu16, tf64, 10 }, + + { ti32, ti8, 10 }, { ti32, tu8, 10 }, { ti32, ti16, 10 }, { ti32, tu16, 10 }, + { ti32, ti32, 10 }, { ti32, tu32, 10 }, { ti32, ti64, 10 }, { ti32, tu64, 10 }, + { ti32, tf32, 10 }, { ti32, tf64, 10 }, + + { tu32, ti8, 10 }, { tu32, tu8, 10 }, { tu32, ti16, 10 }, { tu32, tu16, 10 }, + { tu32, ti32, 10 }, { tu32, tu32, 10 }, { tu32, ti64, 10 }, { tu32, tu64, 10 }, + { tu32, tf32, 10 }, { tu32, tf64, 10 }, + + { ti64, ti8, 10 }, { ti64, tu8, 10 }, { ti64, ti16, 10 }, { ti64, tu16, 10 }, + { ti64, ti32, 10 }, { ti64, tu32, 10 }, { ti64, ti64, 10 }, { ti64, tu64, 10 }, + { ti64, tf32, 10 }, { ti64, tf64, 10 }, + + { tu64, ti8, 10 }, { tu64, tu8, 10 }, { tu64, ti16, 10 }, { tu64, tu16, 10 }, + { tu64, ti32, 10 }, { tu64, tu32, 10 }, { tu64, ti64, 10 }, { tu64, tu64, 10 }, + { tu64, tf32, 10 }, { tu64, tf64, 10 }, + + { tf32, ti8, 10 }, { tf32, tu8, 10 }, { tf32, ti16, 10 }, { tf32, tu16, 10 }, + { tf32, ti32, 10 }, { tf32, tu32, 10 }, { tf32, ti64, 10 }, { tf32, tu64, 10 }, + { tf32, tf32, 10 }, { tf32, tf64, 10 }, + + { tf64, ti8, 10 }, { tf64, tu8, 10 }, { tf64, ti16, 10 }, { tf64, tu16, 10 }, + { tf64, ti32, 10 }, { tf64, tu32, 10 }, { tf64, ti64, 10 }, { tf64, tu64, 10 }, + { tf64, tf32, 10 }, { tf64, tf64, 10 }, + + /* value good in all signed types (-4) */ + { ti8, ti8, -4 }, { ti8, ti16, -4 }, + { ti8, ti32, -4 }, { ti8, ti64, -4 }, + { ti8, tf32, -4 }, { ti8, tf64, -4 }, + + { ti16, ti8, -4 }, { ti16, ti16, -4 }, + { ti16, ti32, -4 }, { ti16, ti64, -4 }, + { ti16, tf32, -4 }, + + { ti32, ti8, -4 }, { ti32, ti16, -4 }, + { ti32, ti32, -4 }, { ti32, ti64, -4 }, + { ti32, tf32, -4 }, { ti32, tf64, -4 }, + + { ti64, ti8, -4 }, { ti64, ti16, -4 }, + { ti64, ti32, -4 }, { ti64, ti64, -4 }, + { ti64, tf32, -4 }, + + { tf32, ti8, -4 }, { tf32, ti16, -4 }, + { tf32, ti32, -4 }, { tf32, ti64, -4 }, + { tf32, tf32, -4 }, + + { tf64, ti8, -4 }, { tf64, ti16, -4 }, + { tf64, ti32, -4 }, { tf64, ti64, -4 }, + { tf64, tf32, -4 }, { tf64, tf64, -4 }, + + /* value good in u8 and up (175) */ + { tu8, tu8, 175 }, { tu8, ti16, 175 }, { tu8, tu16, 175 }, + { tu8, ti32, 175 }, { tu8, tu32, 175 }, { tu8, ti64, 175 }, { tu8, tu64, 175 }, + { tu8, tf32, 175 }, { tu8, tf64, 175 }, + + { ti16, tu8, 175 }, { ti16, ti16, 175 }, { ti16, tu16, 175 }, + { ti16, ti32, 175 }, { ti16, tu32, 175 }, { ti16, ti64, 175 }, { ti16, tu64, 175 }, + { ti16, tf32, 175 }, { ti16, tf64, 175 }, + + { tu16, tu8, 175 }, { tu16, ti16, 175 }, { tu16, tu16, 175 }, + { tu16, ti32, 175 }, { tu16, tu32, 175 }, { tu16, ti64, 175 }, { tu16, tu64, 175 }, + { tu16, tf32, 175 }, { tu16, tf64, 175 }, + + { ti32, tu8, 175 }, { ti32, ti16, 175 }, { ti32, tu16, 175 }, + { ti32, ti32, 175 }, { ti32, tu32, 175 }, { ti32, ti64, 175 }, { ti32, tu64, 175 }, + { ti32, tf32, 175 }, { ti32, tf64, 175 }, + + { tu32, tu8, 175 }, { tu32, ti16, 175 }, { tu32, tu16, 175 }, + { tu32, ti32, 175 }, { tu32, tu32, 175 }, { tu32, ti64, 175 }, { tu32, tu64, 175 }, + { tu32, tf32, 175 }, { tu32, tf64, 175 }, + + { ti64, tu8, 175 }, { ti64, ti16, 175 }, { ti64, tu16, 175 }, + { ti64, ti32, 175 }, { ti64, tu32, 175 }, { ti64, ti64, 175 }, { ti64, tu64, 175 }, + { ti64, tf32, 175 }, { ti64, tf64, 175 }, + + { tu64, tu8, 175 }, { tu64, ti16, 175 }, { tu64, tu16, 175 }, + { tu64, ti32, 175 }, { tu64, tu32, 175 }, { tu64, ti64, 175 }, { tu64, tu64, 175 }, + { tu64, tf32, 175 }, { tu64, tf64, 175 }, + + { tf32, tu8, 175 }, { tf32, ti16, 175 }, { tf32, tu16, 175 }, + { tf32, ti32, 175 }, { tf32, tu32, 175 }, { tf32, ti64, 175 }, { tf32, tu64, 175 }, + { tf32, tf32, 175 }, { tf32, tf64, 175 }, + + { tf64, tu8, 175 }, { tf64, ti16, 175 }, { tf64, tu16, 175 }, + { tf64, ti32, 175 }, { tf64, tu32, 175 }, { tf64, ti64, 175 }, { tf64, tu64, 175 }, + { tf64, tf32, 175 }, { tf64, tf64, 175 }, + + /* value good in u16 and up (41259) */ + { tu16, tu16, 41259 }, + { tu16, ti32, 41259 }, { tu16, ti64, 41259 }, { tu16, tu64, 41259 }, + { tu16, tf32, 41259 }, { tu16, tf64, 41259 }, + + { ti32, tu16, 41259 }, + { ti32, ti32, 41259 }, { ti32, tu32, 41259 }, { ti32, ti64, 41259 }, { ti32, tu64, 41259 }, + { ti32, tf32, 41259 }, { ti32, tf64, 41259 }, + + { tu32, tu16, 41259 }, + { tu32, ti32, 41259 }, { tu32, tu32, 41259 }, { tu32, ti64, 41259 }, { tu32, tu64, 41259 }, + { tu32, tf32, 41259 }, { tu32, tf64, 41259 }, + + { ti64, tu16, 41259 }, + { ti64, ti32, 41259 }, { ti64, tu32, 41259 }, { ti64, ti64, 41259 }, { ti64, tu64, 41259 }, + { ti64, tf32, 41259 }, { ti64, tf64, 41259 }, + + { tu64, tu16, 41259 }, + { tu64, ti32, 41259 }, { tu64, tu32, 41259 }, { tu64, ti64, 41259 }, { tu64, tu64, 41259 }, + { tu64, tf32, 41259 }, { tu64, tf64, 41259 }, + + { tf32, tu16, 41259 }, + { tf32, ti32, 41259 }, { tf32, tu32, 41259 }, { tf32, ti64, 41259 }, { tf32, tu64, 41259 }, + { tf32, tf32, 41259 }, { tf32, tf64, 41259 }, + + { tf64, tu16, 41259 }, + { tf64, ti32, 41259 }, { tf64, tu32, 41259 }, { tf64, ti64, 41259 }, { tf64, tu64, 41259 }, + { tf64, tf32, 41259 }, { tf64, tf64, 41259 }, + + /* value good in u32 and up (3758096384) */ + { tu32, tu32, 3758096384 }, { tu32, ti64, 3758096384 }, { tu32, tu64, 3758096384 }, + { tu32, tf32, 3758096384 }, { tu32, tf64, 3758096384 }, + + { ti64, tu32, 3758096384 }, { ti64, ti64, 3758096384 }, { ti64, tu64, 3758096384 }, + { ti64, tf32, 3758096384 }, { ti64, tf64, 3758096384 }, + + { tu64, tu32, 3758096384 }, { tu64, ti64, 3758096384 }, { tu64, tu64, 3758096384 }, + { tu64, tf32, 3758096384 }, { tu64, tf64, 3758096384 }, + + { tf32, tu32, 3758096384 }, { tf32, ti64, 3758096384 }, { tf32, tu64, 3758096384 }, + { tf32, tf32, 3758096384 }, { tf32, tf64, 3758096384 }, + + { tf64, tu32, 3758096384 }, { tf64, ti64, 3758096384 }, { tf64, tu64, 3758096384 }, + { tf64, tf32, 3758096384 }, { tf64, tf64, 3758096384 }, + + /* value good in u64 and up (16717361816799281152) */ + { tu64, tu64, 16717361816799281152 }, + { tu64, tf32, 16717361816799281152 }, { tu64, tf64, 16717361816799281152 }, + + { tf32, tu64, 16717361816799281152 }, + { tf32, tf32, 16717361816799281152 }, { tf32, tf64, 16717361816799281152 }, + + { tf64, tu64, 16717361816799281152 }, + { tf64, tf32, 16717361816799281152 }, { tf64, tf64, 16717361816799281152 }, +} + +func main() { + for i:=0; i 1e-6 { + println(r, "!= 1.292308") + panic(0) + } + d = i + 0.1384615 + if d < 0 { + d = - d + } + if d > 1e-6 { + println(i, "!= -0.1384615") + panic(0) + } + + c := *(*complex128)(unsafe.Pointer(&c0)) + if c != c0 { + println(c, "!=", c) + panic(0) + } + + var a interface{} + switch c := reflect.ValueOf(a); c.Kind() { + case reflect.Complex64, reflect.Complex128: + v := c.Complex() + _, _ = complex128(v), true + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/cplx4.go b/platform/dbops/binaries/go/go/test/ken/cplx4.go new file mode 100644 index 0000000000000000000000000000000000000000..97d5d16f4aae56470336b0e29624f48191e74cbe --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/cplx4.go @@ -0,0 +1,61 @@ +// run + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test complex numbers,including fmt support. +// Used to crash. + +package main + +import "fmt" + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func want(s, w string) { + if s != w { + panic(s + " != " + w) + } +} + +func doprint(c complex128, w string) { + s := fmt.Sprintf("%f", c) + want(s, w) +} + +func main() { + + // constants + s := fmt.Sprintf("%f", -C1) + want(s, "(-5.000000-6.000000i)") + doprint(C1, "(5.000000+6.000000i)") + + // variables + c1 := C1 + s = fmt.Sprintf("%f", c1) + want(s, "(5.000000+6.000000i)") + doprint(c1, "(5.000000+6.000000i)") + + // 128 + c2 := complex128(C1) + s = fmt.Sprintf("%G", c2) + want(s, "(5+6i)") + + // real, imag, complex + c3 := complex(real(c2)+3, imag(c2)-5) + c2 + s = fmt.Sprintf("%G", c3) + want(s, "(13+7i)") + + // compiler used to crash on nested divide + c4 := complex(real(c3/2), imag(c3/2)) + if c4 != c3/2 { + fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4) + panic(0) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/cplx5.go b/platform/dbops/binaries/go/go/test/ken/cplx5.go new file mode 100644 index 0000000000000000000000000000000000000000..4e8f4433d3cb2e076dd6b021608ee6d8de202ac3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/cplx5.go @@ -0,0 +1,72 @@ +// run + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test compound types made of complex numbers. + +package main + +var a [12]complex128 +var s []complex128 +var c chan complex128 +var f struct { + c complex128 +} +var m map[complex128]complex128 + +func main() { + // array of complex128 + for i := 0; i < len(a); i++ { + a[i] = complex(float64(i), float64(-i)) + } + if a[5] != 5-5i { + panic(a[5]) + } + + // slice of complex128 + s = make([]complex128, len(a)) + for i := 0; i < len(s); i++ { + s[i] = a[i] + } + if s[5] != 5-5i { + panic(s[5]) + } + + // chan + c = make(chan complex128) + go chantest(c) + vc := <-c + if vc != 5-5i { + panic(vc) + } + + // pointer of complex128 + v := a[5] + pv := &v + if *pv != 5-5i { + panic(*pv) + } + + // field of complex128 + f.c = a[5] + if f.c != 5-5i { + panic(f.c) + } + + // map of complex128 + m = make(map[complex128]complex128) + for i := 0; i < len(s); i++ { + m[-a[i]] = a[i] + } + if m[5i-5] != 5-5i { + panic(m[5i-5]) + } + vm := m[complex(-5, 5)] + if vm != 5-5i { + panic(vm) + } +} + +func chantest(c chan complex128) { c <- a[5] } diff --git a/platform/dbops/binaries/go/go/test/ken/divconst.go b/platform/dbops/binaries/go/go/test/ken/divconst.go new file mode 100644 index 0000000000000000000000000000000000000000..670e07417aad71317faa48547da969b8501901d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/divconst.go @@ -0,0 +1,634 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test integer division by constants. + +package main + +import "math/rand" + +const Count = 1e5 + +func i64rand() int64 { + for { + a := int64(rand.Uint32()) + a = (a << 32) | int64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i64test(a, b, c int64) { + d := a / c + if d != b { + println("i64", a, b, c, d) + panic("fail") + } +} + +func i64run() { + var a, b int64 + + for i := 0; i < Count; i++ { + a = i64rand() + + b = a / 1 + i64test(a, b, 1) + b = a / 2 + i64test(a, b, 2) + b = a / 3 + i64test(a, b, 3) + b = a / 4 + i64test(a, b, 4) + b = a / 5 + i64test(a, b, 5) + b = a / 6 + i64test(a, b, 6) + b = a / 7 + i64test(a, b, 7) + b = a / 8 + i64test(a, b, 8) + b = a / 10 + i64test(a, b, 10) + b = a / 16 + i64test(a, b, 16) + b = a / 20 + i64test(a, b, 20) + b = a / 32 + i64test(a, b, 32) + b = a / 60 + i64test(a, b, 60) + b = a / 64 + i64test(a, b, 64) + b = a / 128 + i64test(a, b, 128) + b = a / 256 + i64test(a, b, 256) + b = a / 16384 + i64test(a, b, 16384) + + b = a / -1 + i64test(a, b, -1) + b = a / -2 + i64test(a, b, -2) + b = a / -3 + i64test(a, b, -3) + b = a / -4 + i64test(a, b, -4) + b = a / -5 + i64test(a, b, -5) + b = a / -6 + i64test(a, b, -6) + b = a / -7 + i64test(a, b, -7) + b = a / -8 + i64test(a, b, -8) + b = a / -10 + i64test(a, b, -10) + b = a / -16 + i64test(a, b, -16) + b = a / -20 + i64test(a, b, -20) + b = a / -32 + i64test(a, b, -32) + b = a / -60 + i64test(a, b, -60) + b = a / -64 + i64test(a, b, -64) + b = a / -128 + i64test(a, b, -128) + b = a / -256 + i64test(a, b, -256) + b = a / -16384 + i64test(a, b, -16384) + } +} + +func u64rand() uint64 { + a := uint64(rand.Uint32()) + a = (a << 32) | uint64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + return a +} + +func u64test(a, b, c uint64) { + d := a / c + if d != b { + println("u64", a, b, c, d) + panic("fail") + } +} + +func u64run() { + var a, b uint64 + + for i := 0; i < Count; i++ { + a = u64rand() + + b = a / 1 + u64test(a, b, 1) + b = a / 2 + u64test(a, b, 2) + b = a / 3 + u64test(a, b, 3) + b = a / 4 + u64test(a, b, 4) + b = a / 5 + u64test(a, b, 5) + b = a / 6 + u64test(a, b, 6) + b = a / 7 + u64test(a, b, 7) + b = a / 8 + u64test(a, b, 8) + b = a / 10 + u64test(a, b, 10) + b = a / 16 + u64test(a, b, 16) + b = a / 20 + u64test(a, b, 20) + b = a / 32 + u64test(a, b, 32) + b = a / 60 + u64test(a, b, 60) + b = a / 64 + u64test(a, b, 64) + b = a / 128 + u64test(a, b, 128) + b = a / 256 + u64test(a, b, 256) + b = a / 16384 + u64test(a, b, 16384) + } +} + +func i32rand() int32 { + for { + a := int32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i32test(a, b, c int32) { + d := a / c + if d != b { + println("i32", a, b, c, d) + panic("fail") + } +} + +func i32run() { + var a, b int32 + + for i := 0; i < Count; i++ { + a = i32rand() + + b = a / 1 + i32test(a, b, 1) + b = a / 2 + i32test(a, b, 2) + b = a / 3 + i32test(a, b, 3) + b = a / 4 + i32test(a, b, 4) + b = a / 5 + i32test(a, b, 5) + b = a / 6 + i32test(a, b, 6) + b = a / 7 + i32test(a, b, 7) + b = a / 8 + i32test(a, b, 8) + b = a / 10 + i32test(a, b, 10) + b = a / 16 + i32test(a, b, 16) + b = a / 20 + i32test(a, b, 20) + b = a / 32 + i32test(a, b, 32) + b = a / 60 + i32test(a, b, 60) + b = a / 64 + i32test(a, b, 64) + b = a / 128 + i32test(a, b, 128) + b = a / 256 + i32test(a, b, 256) + b = a / 16384 + i32test(a, b, 16384) + + b = a / -1 + i32test(a, b, -1) + b = a / -2 + i32test(a, b, -2) + b = a / -3 + i32test(a, b, -3) + b = a / -4 + i32test(a, b, -4) + b = a / -5 + i32test(a, b, -5) + b = a / -6 + i32test(a, b, -6) + b = a / -7 + i32test(a, b, -7) + b = a / -8 + i32test(a, b, -8) + b = a / -10 + i32test(a, b, -10) + b = a / -16 + i32test(a, b, -16) + b = a / -20 + i32test(a, b, -20) + b = a / -32 + i32test(a, b, -32) + b = a / -60 + i32test(a, b, -60) + b = a / -64 + i32test(a, b, -64) + b = a / -128 + i32test(a, b, -128) + b = a / -256 + i32test(a, b, -256) + } +} + +func u32rand() uint32 { + a := uint32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + return a +} + +func u32test(a, b, c uint32) { + d := a / c + if d != b { + println("u32", a, b, c, d) + panic("fail") + } +} + +func u32run() { + var a, b uint32 + + for i := 0; i < Count; i++ { + a = u32rand() + + b = a / 1 + u32test(a, b, 1) + b = a / 2 + u32test(a, b, 2) + b = a / 3 + u32test(a, b, 3) + b = a / 4 + u32test(a, b, 4) + b = a / 5 + u32test(a, b, 5) + b = a / 6 + u32test(a, b, 6) + b = a / 7 + u32test(a, b, 7) + b = a / 8 + u32test(a, b, 8) + b = a / 10 + u32test(a, b, 10) + b = a / 16 + u32test(a, b, 16) + b = a / 20 + u32test(a, b, 20) + b = a / 32 + u32test(a, b, 32) + b = a / 60 + u32test(a, b, 60) + b = a / 64 + u32test(a, b, 64) + b = a / 128 + u32test(a, b, 128) + b = a / 256 + u32test(a, b, 256) + b = a / 16384 + u32test(a, b, 16384) + } +} + +func i16rand() int16 { + for { + a := int16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i16test(a, b, c int16) { + d := a / c + if d != b { + println("i16", a, b, c, d) + panic("fail") + } +} + +func i16run() { + var a, b int16 + + for i := 0; i < Count; i++ { + a = i16rand() + + b = a / 1 + i16test(a, b, 1) + b = a / 2 + i16test(a, b, 2) + b = a / 3 + i16test(a, b, 3) + b = a / 4 + i16test(a, b, 4) + b = a / 5 + i16test(a, b, 5) + b = a / 6 + i16test(a, b, 6) + b = a / 7 + i16test(a, b, 7) + b = a / 8 + i16test(a, b, 8) + b = a / 10 + i16test(a, b, 10) + b = a / 16 + i16test(a, b, 16) + b = a / 20 + i16test(a, b, 20) + b = a / 32 + i16test(a, b, 32) + b = a / 60 + i16test(a, b, 60) + b = a / 64 + i16test(a, b, 64) + b = a / 128 + i16test(a, b, 128) + b = a / 256 + i16test(a, b, 256) + b = a / 16384 + i16test(a, b, 16384) + + b = a / -1 + i16test(a, b, -1) + b = a / -2 + i16test(a, b, -2) + b = a / -3 + i16test(a, b, -3) + b = a / -4 + i16test(a, b, -4) + b = a / -5 + i16test(a, b, -5) + b = a / -6 + i16test(a, b, -6) + b = a / -7 + i16test(a, b, -7) + b = a / -8 + i16test(a, b, -8) + b = a / -10 + i16test(a, b, -10) + b = a / -16 + i16test(a, b, -16) + b = a / -20 + i16test(a, b, -20) + b = a / -32 + i16test(a, b, -32) + b = a / -60 + i16test(a, b, -60) + b = a / -64 + i16test(a, b, -64) + b = a / -128 + i16test(a, b, -128) + b = a / -256 + i16test(a, b, -256) + b = a / -16384 + i16test(a, b, -16384) + } +} + +func u16rand() uint16 { + a := uint16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + return a +} + +func u16test(a, b, c uint16) { + d := a / c + if d != b { + println("u16", a, b, c, d) + panic("fail") + } +} + +func u16run() { + var a, b uint16 + + for i := 0; i < Count; i++ { + a = u16rand() + + b = a / 1 + u16test(a, b, 1) + b = a / 2 + u16test(a, b, 2) + b = a / 3 + u16test(a, b, 3) + b = a / 4 + u16test(a, b, 4) + b = a / 5 + u16test(a, b, 5) + b = a / 6 + u16test(a, b, 6) + b = a / 7 + u16test(a, b, 7) + b = a / 8 + u16test(a, b, 8) + b = a / 10 + u16test(a, b, 10) + b = a / 16 + u16test(a, b, 16) + b = a / 20 + u16test(a, b, 20) + b = a / 32 + u16test(a, b, 32) + b = a / 60 + u16test(a, b, 60) + b = a / 64 + u16test(a, b, 64) + b = a / 128 + u16test(a, b, 128) + b = a / 256 + u16test(a, b, 256) + b = a / 16384 + u16test(a, b, 16384) + } +} + +func i8rand() int8 { + for { + a := int8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i8test(a, b, c int8) { + d := a / c + if d != b { + println("i8", a, b, c, d) + panic("fail") + } +} + +func i8run() { + var a, b int8 + + for i := 0; i < Count; i++ { + a = i8rand() + + b = a / 1 + i8test(a, b, 1) + b = a / 2 + i8test(a, b, 2) + b = a / 3 + i8test(a, b, 3) + b = a / 4 + i8test(a, b, 4) + b = a / 5 + i8test(a, b, 5) + b = a / 6 + i8test(a, b, 6) + b = a / 7 + i8test(a, b, 7) + b = a / 8 + i8test(a, b, 8) + b = a / 10 + i8test(a, b, 10) + b = a / 8 + i8test(a, b, 8) + b = a / 20 + i8test(a, b, 20) + b = a / 32 + i8test(a, b, 32) + b = a / 60 + i8test(a, b, 60) + b = a / 64 + i8test(a, b, 64) + b = a / 127 + i8test(a, b, 127) + + b = a / -1 + i8test(a, b, -1) + b = a / -2 + i8test(a, b, -2) + b = a / -3 + i8test(a, b, -3) + b = a / -4 + i8test(a, b, -4) + b = a / -5 + i8test(a, b, -5) + b = a / -6 + i8test(a, b, -6) + b = a / -7 + i8test(a, b, -7) + b = a / -8 + i8test(a, b, -8) + b = a / -10 + i8test(a, b, -10) + b = a / -8 + i8test(a, b, -8) + b = a / -20 + i8test(a, b, -20) + b = a / -32 + i8test(a, b, -32) + b = a / -60 + i8test(a, b, -60) + b = a / -64 + i8test(a, b, -64) + b = a / -128 + i8test(a, b, -128) + } +} + +func u8rand() uint8 { + a := uint8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + return a +} + +func u8test(a, b, c uint8) { + d := a / c + if d != b { + println("u8", a, b, c, d) + panic("fail") + } +} + +func u8run() { + var a, b uint8 + + for i := 0; i < Count; i++ { + a = u8rand() + + b = a / 1 + u8test(a, b, 1) + b = a / 2 + u8test(a, b, 2) + b = a / 3 + u8test(a, b, 3) + b = a / 4 + u8test(a, b, 4) + b = a / 5 + u8test(a, b, 5) + b = a / 6 + u8test(a, b, 6) + b = a / 7 + u8test(a, b, 7) + b = a / 8 + u8test(a, b, 8) + b = a / 10 + u8test(a, b, 10) + b = a / 8 + u8test(a, b, 8) + b = a / 20 + u8test(a, b, 20) + b = a / 32 + u8test(a, b, 32) + b = a / 60 + u8test(a, b, 60) + b = a / 64 + u8test(a, b, 64) + b = a / 128 + u8test(a, b, 128) + b = a / 184 + u8test(a, b, 184) + } +} + +func main() { + xtest() + i64run() + u64run() + i32run() + u32run() + i16run() + u16run() + i8run() + u8run() +} + +func xtest() { +} diff --git a/platform/dbops/binaries/go/go/test/ken/divmod.go b/platform/dbops/binaries/go/go/test/ken/divmod.go new file mode 100644 index 0000000000000000000000000000000000000000..f1bd56ec66b85143316214eccc499aeba0816b1e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/divmod.go @@ -0,0 +1,249 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test integer division and modulus. + +package main + +const ( + // example from the spec + n1 = +5 + n2 = -5 + d1 = +3 + d2 = -3 + + q1 = +1 + q2 = -1 + q3 = -1 + q4 = +1 + + r1 = +2 + r2 = -2 + r3 = +2 + r4 = -2 +) + +func main() { + /* ideals */ + if n1/d1 != q1 || n1%d1 != r1 { + println("ideal-1", n1, d1, n1/d1, n1%d1) + panic("fail") + } + if n2/d1 != q2 || n2%d1 != r2 { + println("ideal-2", n2, d1, n2/d1, n2%d1) + panic("fail") + } + if n1/d2 != q3 || n1%d2 != r3 { + println("ideal-3", n1, d2, n1/d2, n1%d2) + panic("fail") + } + if n2/d2 != q4 || n2%d2 != r4 { + println("ideal-4", n2, d2, n2/d2, n2%d2) + panic("fail") + } + + /* int */ + var in1 int = +5 + var in2 int = -5 + var id1 int = +3 + var id2 int = -3 + + if in1/id1 != q1 || in1%id1 != r1 { + println("int-1", in1, id1, in1/id1, in1%id1) + panic("fail") + } + if in2/id1 != q2 || in2%id1 != r2 { + println("int-2", in2, id1, in2/id1, in2%id1) + panic("fail") + } + if in1/id2 != q3 || in1%id2 != r3 { + println("int-3", in1, id2, in1/id2, in1%id2) + panic("fail") + } + if in2/id2 != q4 || in2%id2 != r4 { + println("int-4", in2, id2, in2/id2, in2%id2) + panic("fail") + } + + /* int8 */ + var bn1 int8 = +5 + var bn2 int8 = -5 + var bd1 int8 = +3 + var bd2 int8 = -3 + + if bn1/bd1 != q1 || bn1%bd1 != r1 { + println("int8-1", bn1, bd1, bn1/bd1, bn1%bd1) + panic("fail") + } + if bn2/bd1 != q2 || bn2%bd1 != r2 { + println("int8-2", bn2, bd1, bn2/bd1, bn2%bd1) + panic("fail") + } + if bn1/bd2 != q3 || bn1%bd2 != r3 { + println("int8-3", bn1, bd2, bn1/bd2, bn1%bd2) + panic("fail") + } + if bn2/bd2 != q4 || bn2%bd2 != r4 { + println("int8-4", bn2, bd2, bn2/bd2, bn2%bd2) + panic("fail") + } + + /* int16 */ + var sn1 int16 = +5 + var sn2 int16 = -5 + var sd1 int16 = +3 + var sd2 int16 = -3 + + if sn1/sd1 != q1 || sn1%sd1 != r1 { + println("int16-1", sn1, sd1, sn1/sd1, sn1%sd1) + panic("fail") + } + if sn2/sd1 != q2 || sn2%sd1 != r2 { + println("int16-2", sn2, sd1, sn2/sd1, sn2%sd1) + panic("fail") + } + if sn1/sd2 != q3 || sn1%sd2 != r3 { + println("int16-3", sn1, sd2, sn1/sd2, sn1%sd2) + panic("fail") + } + if sn2/sd2 != q4 || sn2%sd2 != r4 { + println("int16-4", sn2, sd2, sn2/sd2, sn2%sd2) + panic("fail") + } + + /* int32 */ + var ln1 int32 = +5 + var ln2 int32 = -5 + var ld1 int32 = +3 + var ld2 int32 = -3 + + if ln1/ld1 != q1 || ln1%ld1 != r1 { + println("int32-1", ln1, ld1, ln1/ld1, ln1%ld1) + panic("fail") + } + if ln2/ld1 != q2 || ln2%ld1 != r2 { + println("int32-2", ln2, ld1, ln2/ld1, ln2%ld1) + panic("fail") + } + if ln1/ld2 != q3 || ln1%ld2 != r3 { + println("int32-3", ln1, ld2, ln1/ld2, ln1%ld2) + panic("fail") + } + if ln2/ld2 != q4 || ln2%ld2 != r4 { + println("int32-4", ln2, ld2, ln2/ld2, ln2%ld2) + panic("fail") + } + + /* int64 */ + var qn1 int64 = +5 + var qn2 int64 = -5 + var qd1 int64 = +3 + var qd2 int64 = -3 + + if qn1/qd1 != q1 || qn1%qd1 != r1 { + println("int64-1", qn1, qd1, qn1/qd1, qn1%qd1) + panic("fail") + } + if qn2/qd1 != q2 || qn2%qd1 != r2 { + println("int64-2", qn2, qd1, qn2/qd1, qn2%qd1) + panic("fail") + } + if qn1/qd2 != q3 || qn1%qd2 != r3 { + println("int64-3", qn1, qd2, qn1/qd2, qn1%qd2) + panic("fail") + } + if qn2/qd2 != q4 || qn2%qd2 != r4 { + println("int64-4", qn2, qd2, qn2/qd2, qn2%qd2) + panic("fail") + } + + if n1/qd1 != q1 || n1%qd1 != r1 { + println("mixed int64-1", n1, qd1, n1/qd1, n1%qd1) + panic("fail") + } + if n2/qd1 != q2 || n2%qd1 != r2 { + println("mixed int64-2", n2, qd1, n2/qd1, n2%qd1) + panic("fail") + } + if n1/qd2 != q3 || n1%qd2 != r3 { + println("mixed int64-3", n1, qd2, n1/qd2, n1%qd2) + panic("fail") + } + if n2/qd2 != q4 || n2%qd2 != r4 { + println("mixed int64-4", n2, qd2, n2/qd2, n2%qd2) + panic("fail") + } + + if qn1/d1 != q1 || qn1%d1 != r1 { + println("mixed int64-5", qn1, d1, qn1/d1, qn1%d1) + panic("fail") + } + if qn2/d1 != q2 || qn2%d1 != r2 { + println("mixed int64-6", qn2, d1, qn2/d1, qn2%d1) + panic("fail") + } + if qn1/d2 != q3 || qn1%d2 != r3 { + println("mixed int64-7", qn1, d2, qn1/d2, qn1%d2) + panic("fail") + } + if qn2/d2 != q4 || qn2%d2 != r4 { + println("mixed int64-8", qn2, d2, qn2/d2, qn2%d2) + panic("fail") + } + + /* uint */ + var uin1 uint = +5 + var uid1 uint = +3 + + if uin1/uid1 != q1 || uin1%uid1 != r1 { + println("uint", uin1, uid1, uin1/uid1, uin1%uid1) + panic("fail") + } + + /* uint8 */ + var ubn1 uint8 = +5 + var ubd1 uint8 = +3 + + if ubn1/ubd1 != q1 || ubn1%ubd1 != r1 { + println("uint8", ubn1, ubd1, ubn1/ubd1, ubn1%ubd1) + panic("fail") + } + + /* uint16 */ + var usn1 uint16 = +5 + var usd1 uint16 = +3 + + if usn1/usd1 != q1 || usn1%usd1 != r1 { + println("uint16", usn1, usd1, usn1/usd1, usn1%usd1) + panic("fail") + } + + /* uint32 */ + var uln1 uint32 = +5 + var uld1 uint32 = +3 + + if uln1/uld1 != q1 || uln1%uld1 != r1 { + println("uint32", uln1, uld1, uln1/uld1, uln1%uld1) + panic("fail") + } + + /* uint64 */ + var uqn1 uint64 = +5 + var uqd1 uint64 = +3 + + if uqn1/uqd1 != q1 || uqn1%uqd1 != r1 { + println("uint64", uqn1, uqd1, uqn1/uqd1, uqn1%uqd1) + panic("fail") + } + if n1/uqd1 != q1 || n1%uqd1 != r1 { + println("mixed uint64-1", n1, uqd1, n1/uqd1, n1%uqd1) + panic("fail") + } + if uqn1/d1 != q1 || uqn1%d1 != r1 { + println("mixed uint64-2", uqn1, d1, uqn1/d1, uqn1%d1) + panic("fail") + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/embed.go b/platform/dbops/binaries/go/go/test/ken/embed.go new file mode 100644 index 0000000000000000000000000000000000000000..f7ca0665e26f87f896be328f5c08737c3b16c317 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/embed.go @@ -0,0 +1,319 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test embedded fields of structs, including methods. + +package main + + +type I interface { + test1() int + test2() int + test3() int + test4() int + test5() int + test6() int + test7() int +} + +/****** + ****** + ******/ + +type SubpSubp struct { + a7 int + a int +} + +func (p *SubpSubp) test7() int { + if p.a != p.a7 { + println("SubpSubp", p, p.a7) + panic("fail") + } + return p.a +} +func (p *SubpSubp) testx() { println("SubpSubp", p, p.a7) } + +/****** + ****** + ******/ + +type SubpSub struct { + a6 int + SubpSubp + a int +} + +func (p *SubpSub) test6() int { + if p.a != p.a6 { + println("SubpSub", p, p.a6) + panic("fail") + } + return p.a +} +func (p *SubpSub) testx() { println("SubpSub", p, p.a6) } + +/****** + ****** + ******/ + +type SubSubp struct { + a5 int + a int +} + +func (p *SubSubp) test5() int { + if p.a != p.a5 { + println("SubpSub", p, p.a5) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type SubSub struct { + a4 int + a int +} + +func (p *SubSub) test4() int { + if p.a != p.a4 { + println("SubpSub", p, p.a4) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type Subp struct { + a3 int + *SubpSubp + SubpSub + a int +} + +func (p *Subp) test3() int { + if p.a != p.a3 { + println("SubpSub", p, p.a3) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type Sub struct { + a2 int + *SubSubp + SubSub + a int +} + +func (p *Sub) test2() int { + if p.a != p.a2 { + println("SubpSub", p, p.a2) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type S struct { + a1 int + Sub + *Subp + a int +} + +func (p *S) test1() int { + if p.a != p.a1 { + println("SubpSub", p, p.a1) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +func main() { + var i I + var s *S + + // allocate + s = new(S) + s.Subp = new(Subp) + s.Sub.SubSubp = new(SubSubp) + s.Subp.SubpSubp = new(SubpSubp) + + // explicit assignment + s.a = 1 + s.Sub.a = 2 + s.Subp.a = 3 + s.Sub.SubSub.a = 4 + s.Sub.SubSubp.a = 5 + s.Subp.SubpSub.a = 6 + s.Subp.SubpSubp.a = 7 + + // embedded (unique) assignment + s.a1 = 1 + s.a2 = 2 + s.a3 = 3 + s.a4 = 4 + s.a5 = 5 + s.a6 = 6 + s.a7 = 7 + + // unique calls with explicit & + if s.test1() != 1 { + println("t1", 1) + panic("fail") + } + if (&s.Sub).test2() != 2 { + println("t1", 2) + panic("fail") + } + if s.Subp.test3() != 3 { + println("t1", 3) + panic("fail") + } + if (&s.Sub.SubSub).test4() != 4 { + println("t1", 4) + panic("fail") + } + if s.Sub.SubSubp.test5() != 5 { + println("t1", 5) + panic("fail") + } + if (&s.Subp.SubpSub).test6() != 6 { + println("t1", 6) + panic("fail") + } + if s.Subp.SubpSubp.test7() != 7 { + println("t1", 7) + panic("fail") + } + + // automatic & + if s.Sub.test2() != 2 { + println("t2", 2) + panic("fail") + } + if s.Sub.SubSub.test4() != 4 { + println("t2", 4) + panic("fail") + } + if s.Subp.SubpSub.test6() != 6 { + println("t2", 6) + panic("fail") + } + + // embedded calls + if s.test1() != s.a1 { + println("t3", 1) + panic("fail") + } + if s.test2() != s.a2 { + println("t3", 2) + panic("fail") + } + if s.test3() != s.a3 { + println("t3", 3) + panic("fail") + } + if s.test4() != s.a4 { + println("t3", 4) + panic("fail") + } + if s.test5() != s.a5 { + println("t3", 5) + panic("fail") + } + if s.test6() != s.a6 { + println("t3", 6) + panic("fail") + } + if s.test7() != s.a7 { + println("t3", 7) + panic("fail") + } + + // run it through an interface + i = s + s = i.(*S) + + // same as t3 + if s.test1() != s.a1 { + println("t4", 1) + panic("fail") + } + if s.test2() != s.a2 { + println("t4", 2) + panic("fail") + } + if s.test3() != s.a3 { + println("t4", 3) + panic("fail") + } + if s.test4() != s.a4 { + println("t4", 4) + panic("fail") + } + if s.test5() != s.a5 { + println("t4", 5) + panic("fail") + } + if s.test6() != s.a6 { + println("t4", 6) + panic("fail") + } + if s.test7() != s.a7 { + println("t4", 7) + panic("fail") + } + + // call interface + if i.test1() != s.test1() { + println("t5", 1) + panic("fail") + } + if i.test2() != s.test2() { + println("t5", 2) + panic("fail") + } + if i.test3() != s.test3() { + println("t5", 3) + panic("fail") + } + if i.test4() != s.test4() { + println("t5", 4) + panic("fail") + } + if i.test5() != s.test5() { + println("t5", 5) + panic("fail") + } + if i.test6() != s.test6() { + println("t5", 6) + panic("fail") + } + if i.test7() != s.test7() { + println("t5", 7) + panic("fail") + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/for.go b/platform/dbops/binaries/go/go/test/ken/for.go new file mode 100644 index 0000000000000000000000000000000000000000..db35548db8511744778b368bd4a8d8a1702837f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/for.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple for loop. + +package main + +func +main() { + var t,i int; + + for i=0; i<100; i=i+1 { + t = t+i; + } + if t != 50*99 { panic(t); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/interbasic.go b/platform/dbops/binaries/go/go/test/ken/interbasic.go new file mode 100644 index 0000000000000000000000000000000000000000..d8fbb95a311b19be39796cf00d86db02862b118c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/interbasic.go @@ -0,0 +1,184 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interfaces on basic types. + +package main + +type myint int +type mystring string +type I0 interface{} + +func f() { + var ia, ib I0 + var i myint + var s mystring + + if ia != ib { + panic("1") + } + + i = 1 + ia = i + ib = i + if ia != ib { + panic("2") + } + if ia == nil { + panic("3") + } + + i = 2 + ia = i + if ia == ib { + panic("4") + } + + ia = nil + if ia == ib { + panic("5") + } + + ib = nil + if ia != ib { + panic("6") + } + + if ia != nil { + panic("7") + } + + s = "abc" + ia = s + ib = nil + if ia == ib { + panic("8") + } + + s = "def" + ib = s + if ia == ib { + panic("9") + } + + s = "abc" + ib = s + if ia != ib { + panic("a") + } +} + +func main() { + var ia [20]I0 + var b bool + var s string + var i8 int8 + var i16 int16 + var i32 int32 + var i64 int64 + var u8 uint8 + var u16 uint16 + var u32 uint32 + var u64 uint64 + + f() + + ia[0] = "xxx" + ia[1] = 12345 + ia[2] = true + + s = "now is" + ia[3] = s + b = false + ia[4] = b + + i8 = 29 + ia[5] = i8 + i16 = 994 + ia[6] = i16 + i32 = 3434 + ia[7] = i32 + i64 = 1234567 + ia[8] = i64 + + u8 = 12 + ia[9] = u8 + u16 = 799 + ia[10] = u16 + u32 = 4455 + ia[11] = u32 + u64 = 765432 + ia[12] = u64 + + s = ia[0].(string) + if s != "xxx" { + println(0, s) + panic("fail") + } + i32 = int32(ia[1].(int)) + if i32 != 12345 { + println(1, i32) + panic("fail") + } + b = ia[2].(bool) + if b != true { + println(2, b) + panic("fail") + } + + s = ia[3].(string) + if s != "now is" { + println(3, s) + panic("fail") + } + b = ia[4].(bool) + if b != false { + println(4, b) + panic("fail") + } + + i8 = ia[5].(int8) + if i8 != 29 { + println(5, i8) + panic("fail") + } + i16 = ia[6].(int16) + if i16 != 994 { + println(6, i16) + panic("fail") + } + i32 = ia[7].(int32) + if i32 != 3434 { + println(7, i32) + panic("fail") + } + i64 = ia[8].(int64) + if i64 != 1234567 { + println(8, i64) + panic("fail") + } + + u8 = ia[9].(uint8) + if u8 != 12 { + println(5, u8) + panic("fail") + } + u16 = ia[10].(uint16) + if u16 != 799 { + println(6, u16) + panic("fail") + } + u32 = ia[11].(uint32) + if u32 != 4455 { + println(7, u32) + panic("fail") + } + u64 = ia[12].(uint64) + if u64 != 765432 { + println(8, u64) + panic("fail") + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/interfun.go b/platform/dbops/binaries/go/go/test/ken/interfun.go new file mode 100644 index 0000000000000000000000000000000000000000..9432181df2aeef625732c081959ea1a2fdf449aa --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/interfun.go @@ -0,0 +1,59 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interfaces and methods. + +package main + +type S struct { + a,b int; +} + +type I1 interface { + f ()int; +} + +type I2 interface { + g() int; + f() int; +} + +func (this *S) f()int { + return this.a; +} + +func (this *S) g()int { + return this.b; +} + +func +main() { + var i1 I1; + var i2 I2; + var g *S; + + s := new(S); + s.a = 5; + s.b = 6; + + // call structure + if s.f() != 5 { panic(11); } + if s.g() != 6 { panic(12); } + + i1 = s; // convert S to I1 + i2 = i1.(I2); // convert I1 to I2 + + // call interface + if i1.f() != 5 { panic(21); } + if i2.f() != 5 { panic(22); } + if i2.g() != 6 { panic(23); } + + g = i1.(*S); // convert I1 to S + if g != s { panic(31); } + + g = i2.(*S); // convert I2 to S + if g != s { panic(32); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/intervar.go b/platform/dbops/binaries/go/go/test/ken/intervar.go new file mode 100644 index 0000000000000000000000000000000000000000..8a2fca0d4bd069979e7e0b7621bfd61b531d06b2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/intervar.go @@ -0,0 +1,69 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test interface assignment. + +package main + +type Iputs interface { + puts (s string) string; +} + +// --------- + +type Print struct { + whoami int; + put Iputs; +} + +func (p *Print) dop() string { + r := " print " + string(p.whoami + '0') + return r + p.put.puts("abc"); +} + +// --------- + +type Bio struct { + whoami int; + put Iputs; +} + +func (b *Bio) puts(s string) string { + r := " bio " + string(b.whoami + '0') + return r + b.put.puts(s); +} + +// --------- + +type File struct { + whoami int; + put Iputs; +} + +func (f *File) puts(s string) string { + return " file " + string(f.whoami + '0') + " -- " + s +} + +func +main() { + p := new(Print); + b := new(Bio); + f := new(File); + + p.whoami = 1; + p.put = b; + + b.whoami = 2; + b.put = f; + + f.whoami = 3; + + r := p.dop(); + expected := " print 1 bio 2 file 3 -- abc" + if r != expected { + panic(r + " != " + expected) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/label.go b/platform/dbops/binaries/go/go/test/ken/label.go new file mode 100644 index 0000000000000000000000000000000000000000..fcb3e611d9d6a62ab3f9bb5fed3d7da035c4b3ca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/label.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test goto and labels. + +package main + +func main() { + i := 0 + if false { + goto gogoloop + } + if false { + goto gogoloop + } + if false { + goto gogoloop + } + goto gogoloop + + // backward declared +loop: + i = i + 1 + if i < 100 { + goto loop + } + return + +gogoloop: + goto loop +} diff --git a/platform/dbops/binaries/go/go/test/ken/litfun.go b/platform/dbops/binaries/go/go/test/ken/litfun.go new file mode 100644 index 0000000000000000000000000000000000000000..e241d4edb798a76c9493cc7169b27c842560ff8c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/litfun.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple function literals. + +package main + +func +main() { + x := func(a int)int { + x := func(a int)int { + x := func(a int)int { + return a+5; + }; + return x(a)+7; + }; + return x(a)+11; + }; + if x(3) != 3+5+7+11 { panic(x(3)); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/mfunc.go b/platform/dbops/binaries/go/go/test/ken/mfunc.go new file mode 100644 index 0000000000000000000000000000000000000000..ef2499194f7add8299c3e8b4a636b765c17acc3f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/mfunc.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple multi-argument multi-valued function. + +package main + +func +main() { + var x,y int; + + x,y = simple(10,20,30); + if x+y != 65 { panic(x+y); } +} + +func +simple(ia,ib,ic int) (oa,ob int) { + return ia+5, ib+ic; +} diff --git a/platform/dbops/binaries/go/go/test/ken/modconst.go b/platform/dbops/binaries/go/go/test/ken/modconst.go new file mode 100644 index 0000000000000000000000000000000000000000..c27bf64bdf501f67ed681628662e1c978f7b2e80 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/modconst.go @@ -0,0 +1,634 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test integer modulus by constants. + +package main + +import "math/rand" + +const Count = 1e5 + +func i64rand() int64 { + for { + a := int64(rand.Uint32()) + a = (a << 32) | int64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i64test(a, b, c int64) { + d := a % c + if d != b { + println("i64", a, b, c, d) + panic("fail") + } +} + +func i64run() { + var a, b int64 + + for i := 0; i < Count; i++ { + a = i64rand() + + b = a % 1 + i64test(a, b, 1) + b = a % 2 + i64test(a, b, 2) + b = a % 3 + i64test(a, b, 3) + b = a % 4 + i64test(a, b, 4) + b = a % 5 + i64test(a, b, 5) + b = a % 6 + i64test(a, b, 6) + b = a % 7 + i64test(a, b, 7) + b = a % 8 + i64test(a, b, 8) + b = a % 10 + i64test(a, b, 10) + b = a % 16 + i64test(a, b, 16) + b = a % 20 + i64test(a, b, 20) + b = a % 32 + i64test(a, b, 32) + b = a % 60 + i64test(a, b, 60) + b = a % 64 + i64test(a, b, 64) + b = a % 128 + i64test(a, b, 128) + b = a % 256 + i64test(a, b, 256) + b = a % 16384 + i64test(a, b, 16384) + + b = a % -1 + i64test(a, b, -1) + b = a % -2 + i64test(a, b, -2) + b = a % -3 + i64test(a, b, -3) + b = a % -4 + i64test(a, b, -4) + b = a % -5 + i64test(a, b, -5) + b = a % -6 + i64test(a, b, -6) + b = a % -7 + i64test(a, b, -7) + b = a % -8 + i64test(a, b, -8) + b = a % -10 + i64test(a, b, -10) + b = a % -16 + i64test(a, b, -16) + b = a % -20 + i64test(a, b, -20) + b = a % -32 + i64test(a, b, -32) + b = a % -60 + i64test(a, b, -60) + b = a % -64 + i64test(a, b, -64) + b = a % -128 + i64test(a, b, -128) + b = a % -256 + i64test(a, b, -256) + b = a % -16384 + i64test(a, b, -16384) + } +} + +func u64rand() uint64 { + a := uint64(rand.Uint32()) + a = (a << 32) | uint64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + return a +} + +func u64test(a, b, c uint64) { + d := a % c + if d != b { + println("u64", a, b, c, d) + panic("fail") + } +} + +func u64run() { + var a, b uint64 + + for i := 0; i < Count; i++ { + a = u64rand() + + b = a % 1 + u64test(a, b, 1) + b = a % 2 + u64test(a, b, 2) + b = a % 3 + u64test(a, b, 3) + b = a % 4 + u64test(a, b, 4) + b = a % 5 + u64test(a, b, 5) + b = a % 6 + u64test(a, b, 6) + b = a % 7 + u64test(a, b, 7) + b = a % 8 + u64test(a, b, 8) + b = a % 10 + u64test(a, b, 10) + b = a % 16 + u64test(a, b, 16) + b = a % 20 + u64test(a, b, 20) + b = a % 32 + u64test(a, b, 32) + b = a % 60 + u64test(a, b, 60) + b = a % 64 + u64test(a, b, 64) + b = a % 128 + u64test(a, b, 128) + b = a % 256 + u64test(a, b, 256) + b = a % 16384 + u64test(a, b, 16384) + } +} + +func i32rand() int32 { + for { + a := int32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i32test(a, b, c int32) { + d := a % c + if d != b { + println("i32", a, b, c, d) + panic("fail") + } +} + +func i32run() { + var a, b int32 + + for i := 0; i < Count; i++ { + a = i32rand() + + b = a % 1 + i32test(a, b, 1) + b = a % 2 + i32test(a, b, 2) + b = a % 3 + i32test(a, b, 3) + b = a % 4 + i32test(a, b, 4) + b = a % 5 + i32test(a, b, 5) + b = a % 6 + i32test(a, b, 6) + b = a % 7 + i32test(a, b, 7) + b = a % 8 + i32test(a, b, 8) + b = a % 10 + i32test(a, b, 10) + b = a % 16 + i32test(a, b, 16) + b = a % 20 + i32test(a, b, 20) + b = a % 32 + i32test(a, b, 32) + b = a % 60 + i32test(a, b, 60) + b = a % 64 + i32test(a, b, 64) + b = a % 128 + i32test(a, b, 128) + b = a % 256 + i32test(a, b, 256) + b = a % 16384 + i32test(a, b, 16384) + + b = a % -1 + i32test(a, b, -1) + b = a % -2 + i32test(a, b, -2) + b = a % -3 + i32test(a, b, -3) + b = a % -4 + i32test(a, b, -4) + b = a % -5 + i32test(a, b, -5) + b = a % -6 + i32test(a, b, -6) + b = a % -7 + i32test(a, b, -7) + b = a % -8 + i32test(a, b, -8) + b = a % -10 + i32test(a, b, -10) + b = a % -16 + i32test(a, b, -16) + b = a % -20 + i32test(a, b, -20) + b = a % -32 + i32test(a, b, -32) + b = a % -60 + i32test(a, b, -60) + b = a % -64 + i32test(a, b, -64) + b = a % -128 + i32test(a, b, -128) + b = a % -256 + i32test(a, b, -256) + } +} + +func u32rand() uint32 { + a := uint32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + return a +} + +func u32test(a, b, c uint32) { + d := a % c + if d != b { + println("u32", a, b, c, d) + panic("fail") + } +} + +func u32run() { + var a, b uint32 + + for i := 0; i < Count; i++ { + a = u32rand() + + b = a % 1 + u32test(a, b, 1) + b = a % 2 + u32test(a, b, 2) + b = a % 3 + u32test(a, b, 3) + b = a % 4 + u32test(a, b, 4) + b = a % 5 + u32test(a, b, 5) + b = a % 6 + u32test(a, b, 6) + b = a % 7 + u32test(a, b, 7) + b = a % 8 + u32test(a, b, 8) + b = a % 10 + u32test(a, b, 10) + b = a % 16 + u32test(a, b, 16) + b = a % 20 + u32test(a, b, 20) + b = a % 32 + u32test(a, b, 32) + b = a % 60 + u32test(a, b, 60) + b = a % 64 + u32test(a, b, 64) + b = a % 128 + u32test(a, b, 128) + b = a % 256 + u32test(a, b, 256) + b = a % 16384 + u32test(a, b, 16384) + } +} + +func i16rand() int16 { + for { + a := int16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i16test(a, b, c int16) { + d := a % c + if d != b { + println("i16", a, b, c, d) + panic("fail") + } +} + +func i16run() { + var a, b int16 + + for i := 0; i < Count; i++ { + a = i16rand() + + b = a % 1 + i16test(a, b, 1) + b = a % 2 + i16test(a, b, 2) + b = a % 3 + i16test(a, b, 3) + b = a % 4 + i16test(a, b, 4) + b = a % 5 + i16test(a, b, 5) + b = a % 6 + i16test(a, b, 6) + b = a % 7 + i16test(a, b, 7) + b = a % 8 + i16test(a, b, 8) + b = a % 10 + i16test(a, b, 10) + b = a % 16 + i16test(a, b, 16) + b = a % 20 + i16test(a, b, 20) + b = a % 32 + i16test(a, b, 32) + b = a % 60 + i16test(a, b, 60) + b = a % 64 + i16test(a, b, 64) + b = a % 128 + i16test(a, b, 128) + b = a % 256 + i16test(a, b, 256) + b = a % 16384 + i16test(a, b, 16384) + + b = a % -1 + i16test(a, b, -1) + b = a % -2 + i16test(a, b, -2) + b = a % -3 + i16test(a, b, -3) + b = a % -4 + i16test(a, b, -4) + b = a % -5 + i16test(a, b, -5) + b = a % -6 + i16test(a, b, -6) + b = a % -7 + i16test(a, b, -7) + b = a % -8 + i16test(a, b, -8) + b = a % -10 + i16test(a, b, -10) + b = a % -16 + i16test(a, b, -16) + b = a % -20 + i16test(a, b, -20) + b = a % -32 + i16test(a, b, -32) + b = a % -60 + i16test(a, b, -60) + b = a % -64 + i16test(a, b, -64) + b = a % -128 + i16test(a, b, -128) + b = a % -256 + i16test(a, b, -256) + b = a % -16384 + i16test(a, b, -16384) + } +} + +func u16rand() uint16 { + a := uint16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + return a +} + +func u16test(a, b, c uint16) { + d := a % c + if d != b { + println("u16", a, b, c, d) + panic("fail") + } +} + +func u16run() { + var a, b uint16 + + for i := 0; i < Count; i++ { + a = u16rand() + + b = a % 1 + u16test(a, b, 1) + b = a % 2 + u16test(a, b, 2) + b = a % 3 + u16test(a, b, 3) + b = a % 4 + u16test(a, b, 4) + b = a % 5 + u16test(a, b, 5) + b = a % 6 + u16test(a, b, 6) + b = a % 7 + u16test(a, b, 7) + b = a % 8 + u16test(a, b, 8) + b = a % 10 + u16test(a, b, 10) + b = a % 16 + u16test(a, b, 16) + b = a % 20 + u16test(a, b, 20) + b = a % 32 + u16test(a, b, 32) + b = a % 60 + u16test(a, b, 60) + b = a % 64 + u16test(a, b, 64) + b = a % 128 + u16test(a, b, 128) + b = a % 256 + u16test(a, b, 256) + b = a % 16384 + u16test(a, b, 16384) + } +} + +func i8rand() int8 { + for { + a := int8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i8test(a, b, c int8) { + d := a % c + if d != b { + println("i8", a, b, c, d) + panic("fail") + } +} + +func i8run() { + var a, b int8 + + for i := 0; i < Count; i++ { + a = i8rand() + + b = a % 1 + i8test(a, b, 1) + b = a % 2 + i8test(a, b, 2) + b = a % 3 + i8test(a, b, 3) + b = a % 4 + i8test(a, b, 4) + b = a % 5 + i8test(a, b, 5) + b = a % 6 + i8test(a, b, 6) + b = a % 7 + i8test(a, b, 7) + b = a % 8 + i8test(a, b, 8) + b = a % 10 + i8test(a, b, 10) + b = a % 8 + i8test(a, b, 8) + b = a % 20 + i8test(a, b, 20) + b = a % 32 + i8test(a, b, 32) + b = a % 60 + i8test(a, b, 60) + b = a % 64 + i8test(a, b, 64) + b = a % 127 + i8test(a, b, 127) + + b = a % -1 + i8test(a, b, -1) + b = a % -2 + i8test(a, b, -2) + b = a % -3 + i8test(a, b, -3) + b = a % -4 + i8test(a, b, -4) + b = a % -5 + i8test(a, b, -5) + b = a % -6 + i8test(a, b, -6) + b = a % -7 + i8test(a, b, -7) + b = a % -8 + i8test(a, b, -8) + b = a % -10 + i8test(a, b, -10) + b = a % -8 + i8test(a, b, -8) + b = a % -20 + i8test(a, b, -20) + b = a % -32 + i8test(a, b, -32) + b = a % -60 + i8test(a, b, -60) + b = a % -64 + i8test(a, b, -64) + b = a % -128 + i8test(a, b, -128) + b = a % -101 + i8test(a, b, -101) + } +} + +func u8rand() uint8 { + a := uint8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + return a +} + +func u8test(a, b, c uint8) { + d := a % c + if d != b { + println("u8", a, b, c, d) + panic("fail") + } +} + +func u8run() { + var a, b uint8 + + for i := 0; i < Count; i++ { + a = u8rand() + + b = a % 1 + u8test(a, b, 1) + b = a % 2 + u8test(a, b, 2) + b = a % 3 + u8test(a, b, 3) + b = a % 4 + u8test(a, b, 4) + b = a % 5 + u8test(a, b, 5) + b = a % 6 + u8test(a, b, 6) + b = a % 7 + u8test(a, b, 7) + b = a % 8 + u8test(a, b, 8) + b = a % 10 + u8test(a, b, 10) + b = a % 8 + u8test(a, b, 8) + b = a % 20 + u8test(a, b, 20) + b = a % 32 + u8test(a, b, 32) + b = a % 60 + u8test(a, b, 60) + b = a % 64 + u8test(a, b, 64) + b = a % 127 + u8test(a, b, 127) + } +} + +func main() { + xtest() + i64run() + u64run() + i32run() + u32run() + i16run() + u16run() + i8run() + u8run() +} + +func xtest() { +} diff --git a/platform/dbops/binaries/go/go/test/ken/ptrfun.go b/platform/dbops/binaries/go/go/test/ken/ptrfun.go new file mode 100644 index 0000000000000000000000000000000000000000..af806cfd9281af8386bfe42fe818a88825c99986 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/ptrfun.go @@ -0,0 +1,45 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test method invocation with pointer receivers and function-valued fields. + +package main + +type C struct { + a int; + x func(p *C)int; +} + +func (this *C) f()int { + return this.a; +} + +func +main() { + var v int; + var c *C; + + c = new(C); + c.a = 6; + c.x = g; + + v = g(c); + if v != 6 { panic(v); } + + v = c.x(c); + if v != 6 { panic(v); } + + v = c.f(); + if v != 6 { panic(v); } +} + +func g(p *C)int { + var v int; + + v = p.a; + if v != 6 { panic(v); } + return p.a; +} diff --git a/platform/dbops/binaries/go/go/test/ken/ptrvar.go b/platform/dbops/binaries/go/go/test/ken/ptrvar.go new file mode 100644 index 0000000000000000000000000000000000000000..d78170c9d25a5b7f05dea58180432642026e87db --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/ptrvar.go @@ -0,0 +1,54 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test pointers and the . (selector) operator on structs. + +package main + +type x2 struct { a,b,c int; d int; }; +var g1 x2; +var g2 struct { a,b,c int; d x2; }; + +func +main() { + var x int; + var s1 *x2; + var s2 *struct { a,b,c int; d x2; }; + + s1 = &g1; + s2 = &g2; + + s1.a = 1; + s1.b = 2; + s1.c = 3; + s1.d = 5; + + s2.a = 7; + s2.b = 11; + s2.c = 13; + s2.d.a = 17; + s2.d.b = 19; + s2.d.c = 23; + s2.d.d = 20; + + if(s2.d.c != 23) { panic(1); } + if(g2.d.c != 23) { panic(2); } + + x = s1.a + + s1.b + + s1.c + + s1.d + + + s2.a + + s2.b + + s2.c + + s2.d.a + + s2.d.b + + s2.d.c + + s2.d.d; + + if(x != 121) { panic(x); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/range.go b/platform/dbops/binaries/go/go/test/ken/range.go new file mode 100644 index 0000000000000000000000000000000000000000..89c14e5c35b56076df5c4a6bb83e29e33d8ad0e1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/range.go @@ -0,0 +1,121 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test 'for range' on arrays, slices, and maps. + +package main + +const size = 16 + +var a [size]byte +var p []byte +var m map[int]byte + +func f(k int) byte { + return byte(k * 10007 % size) +} + +func init() { + p = make([]byte, size) + m = make(map[int]byte) + for k := 0; k < size; k++ { + v := f(k) + a[k] = v + p[k] = v + m[k] = v + } +} + +func main() { + var i int + + /* + * key only + */ + i = 0 + for k := range a { + v := a[k] + if v != f(k) { + println("key array range", k, v, a[k]) + panic("fail") + } + i++ + } + if i != size { + println("key array size", i) + panic("fail") + } + + i = 0 + for k := range p { + v := p[k] + if v != f(k) { + println("key pointer range", k, v, p[k]) + panic("fail") + } + i++ + } + if i != size { + println("key pointer size", i) + panic("fail") + } + + i = 0 + for k := range m { + v := m[k] + if v != f(k) { + println("key map range", k, v, m[k]) + panic("fail") + } + i++ + } + if i != size { + println("key map size", i) + panic("fail") + } + + /* + * key,value + */ + i = 0 + for k, v := range a { + if v != f(k) { + println("key:value array range", k, v, a[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value array size", i) + panic("fail") + } + + i = 0 + for k, v := range p { + if v != f(k) { + println("key:value pointer range", k, v, p[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value pointer size", i) + panic("fail") + } + + i = 0 + for k, v := range m { + if v != f(k) { + println("key:value map range", k, v, m[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value map size", i) + panic("fail") + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/rob1.go b/platform/dbops/binaries/go/go/test/ken/rob1.go new file mode 100644 index 0000000000000000000000000000000000000000..3042a671bfbfd3d2bbb0bb2d93d21ceee354b0c6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/rob1.go @@ -0,0 +1,72 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test general operation using a list implementation. + +package main + +type Item interface { + Print() string +} + +type ListItem struct { + item Item + next *ListItem +} + +type List struct { + head *ListItem +} + +func (list *List) Init() { + list.head = nil +} + +func (list *List) Insert(i Item) { + item := new(ListItem) + item.item = i + item.next = list.head + list.head = item +} + +func (list *List) Print() string { + r := "" + i := list.head + for i != nil { + r += i.item.Print() + i = i.next + } + return r +} + +// Something to put in a list +type Integer struct { + val int +} + +func (this *Integer) Init(i int) *Integer { + this.val = i + return this +} + +func (this *Integer) Print() string { + return string(this.val + '0') +} + +func main() { + list := new(List) + list.Init() + for i := 0; i < 10; i = i + 1 { + integer := new(Integer) + integer.Init(i) + list.Insert(integer) + } + + r := list.Print() + if r != "9876543210" { + panic(r) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/rob2.go b/platform/dbops/binaries/go/go/test/ken/rob2.go new file mode 100644 index 0000000000000000000000000000000000000000..4b4410ee859fc8bfa95ba388e84a7e1d398282ed --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/rob2.go @@ -0,0 +1,280 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test general operation using s-list. +// First Go program ever run (although not in this exact form). + +package main + +import "fmt" + +const nilchar = 0 + +type Atom struct { + str string + integer int + next *Slist /* in hash bucket */ +} + +type List struct { + car *Slist + cdr *Slist +} + +type Slist struct { + isatom bool + isstring bool + //union { + atom Atom + list List + //} u; + +} + +func (this *Slist) Car() *Slist { + return this.list.car +} + +func (this *Slist) Cdr() *Slist { + return this.list.cdr +} + +func (this *Slist) String() string { + return this.atom.str +} + +func (this *Slist) Integer() int { + return this.atom.integer +} + +func (slist *Slist) Free() { + if slist == nil { + return + } + if slist.isatom { + // free(slist.String()); + } else { + slist.Car().Free() + slist.Cdr().Free() + } + // free(slist); +} + +//Slist* atom(byte *s, int i); + +var token int +var peekc int = -1 +var lineno int32 = 1 + +var input string +var inputindex int = 0 +var tokenbuf [100]byte +var tokenlen int = 0 + +const EOF int = -1 + +func main() { + var list *Slist + + OpenFile() + for { + list = Parse() + if list == nil { + break + } + r := list.Print() + list.Free() + if r != "(defn foo (add 12 34))" { + panic(r) + } + break + } +} + +func (slist *Slist) PrintOne(doparen bool) string { + if slist == nil { + return "" + } + var r string + if slist.isatom { + if slist.isstring { + r = slist.String() + } else { + r = fmt.Sprintf("%v", slist.Integer()) + } + } else { + if doparen { + r += "(" + } + r += slist.Car().PrintOne(true) + if slist.Cdr() != nil { + r += " " + r += slist.Cdr().PrintOne(false) + } + if doparen { + r += ")" + } + } + return r +} + +func (slist *Slist) Print() string { + return slist.PrintOne(true) +} + +func Get() int { + var c int + + if peekc >= 0 { + c = peekc + peekc = -1 + } else { + c = int(input[inputindex]) + inputindex++ + if c == '\n' { + lineno = lineno + 1 + } + if c == nilchar { + inputindex = inputindex - 1 + c = EOF + } + } + return c +} + +func WhiteSpace(c int) bool { + return c == ' ' || c == '\t' || c == '\r' || c == '\n' +} + +func NextToken() { + var i, c int + + tokenbuf[0] = nilchar // clear previous token + c = Get() + for WhiteSpace(c) { + c = Get() + } + switch c { + case EOF: + token = EOF + case '(', ')': + token = c + break + default: + for i = 0; i < 100-1; { // sizeof tokenbuf - 1 + tokenbuf[i] = byte(c) + i = i + 1 + c = Get() + if c == EOF { + break + } + if WhiteSpace(c) || c == ')' { + peekc = c + break + } + } + if i >= 100-1 { // sizeof tokenbuf - 1 + panic("atom too long\n") + } + tokenlen = i + tokenbuf[i] = nilchar + if '0' <= tokenbuf[0] && tokenbuf[0] <= '9' { + token = '0' + } else { + token = 'A' + } + } +} + +func Expect(c int) { + if token != c { + print("parse error: expected ", c, "\n") + panic("parse") + } + NextToken() +} + +// Parse a non-parenthesized list up to a closing paren or EOF +func ParseList() *Slist { + var slist, retval *Slist + + slist = new(Slist) + slist.list.car = nil + slist.list.cdr = nil + slist.isatom = false + slist.isstring = false + + retval = slist + for { + slist.list.car = Parse() + if token == ')' || token == EOF { // empty cdr + break + } + slist.list.cdr = new(Slist) + slist = slist.list.cdr + } + return retval +} + +func atom(i int) *Slist { // BUG: uses tokenbuf; should take argument) + var slist *Slist + + slist = new(Slist) + if token == '0' { + slist.atom.integer = i + slist.isstring = false + } else { + slist.atom.str = string(tokenbuf[0:tokenlen]) + slist.isstring = true + } + slist.isatom = true + return slist +} + +func atoi() int { // BUG: uses tokenbuf; should take argument) + var v int = 0 + for i := 0; i < tokenlen && '0' <= tokenbuf[i] && tokenbuf[i] <= '9'; i = i + 1 { + v = 10*v + int(tokenbuf[i]-'0') + } + return v +} + +func Parse() *Slist { + var slist *Slist + + if token == EOF || token == ')' { + return nil + } + if token == '(' { + NextToken() + slist = ParseList() + Expect(')') + return slist + } else { + // Atom + switch token { + case EOF: + return nil + case '0': + slist = atom(atoi()) + case '"', 'A': + slist = atom(0) + default: + slist = nil + print("unknown token: ", token, "\n") + } + NextToken() + return slist + } + return nil +} + +func OpenFile() { + input = "(defn foo (add 12 34))\n\x00" + inputindex = 0 + peekc = -1 // BUG + NextToken() +} diff --git a/platform/dbops/binaries/go/go/test/ken/robfor.go b/platform/dbops/binaries/go/go/test/ken/robfor.go new file mode 100644 index 0000000000000000000000000000000000000000..c6a420b39d7125b07c71dd9c8ab9255ef69059a7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/robfor.go @@ -0,0 +1,58 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test for loops of many forms. + +package main + +func assertequal(is, shouldbe int, msg string) { + if is != shouldbe { + print("assertion fail" + msg + "\n"); + panic(1); + } +} + +func main() { + var i, sum int; + + i = 0; + for { + i = i + 1; + if i > 5 { + break; + } + } + assertequal(i, 6, "break"); + + sum = 0; + for i := 0; i <= 10; i++ { + sum = sum + i; + } + assertequal(sum, 55, "all three"); + + sum = 0; + for i := 0; i <= 10; { + sum = sum + i; + i++; + } + assertequal(sum, 55, "only two"); + + sum = 0; + for sum < 100 { + sum = sum + 9; + } + assertequal(sum, 99 + 9, "only one"); + + sum = 0; + for i := 0; i <= 10; i++ { + if i % 2 == 0 { + continue; + } + sum = sum + i; + } + assertequal(sum, 1+3+5+7+9, "continue"); + +} diff --git a/platform/dbops/binaries/go/go/test/ken/robfunc.go b/platform/dbops/binaries/go/go/test/ken/robfunc.go new file mode 100644 index 0000000000000000000000000000000000000000..885267e30c2a613a1cda64c18b81cb017d8047ba --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/robfunc.go @@ -0,0 +1,96 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test functions of many signatures. + +package main + +func assertequal(is, shouldbe int, msg string) { + if is != shouldbe { + print("assertion fail" + msg + "\n") + panic(1) + } +} + +func f1() { +} + +func f2(a int) { +} + +func f3(a, b int) int { + return a + b +} + +func f4(a, b int, c float64) int { + return (a+b)/2 + int(c) +} + +func f5(a int) int { + return 5 +} + +func f6(a int) (r int) { + return 6 +} + +func f7(a int) (x int, y float64) { + return 7, 7.0 +} + + +func f8(a int) (x int, y float64) { + return 8, 8.0 +} + +type T struct { + x, y int +} + +func (t *T) m10(a int, b float64) int { + return (t.x + a) * (t.y + int(b)) +} + + +func f9(a int) (in int, fl float64) { + i := 9 + f := float64(9) + return i, f +} + + +func main() { + f1() + f2(1) + r3 := f3(1, 2) + assertequal(r3, 3, "3") + r4 := f4(0, 2, 3.0) + assertequal(r4, 4, "4") + r5 := f5(1) + assertequal(r5, 5, "5") + r6 := f6(1) + assertequal(r6, 6, "6") + var r7 int + var s7 float64 + r7, s7 = f7(1) + assertequal(r7, 7, "r7") + assertequal(int(s7), 7, "s7") + var r8 int + var s8 float64 + r8, s8 = f8(1) + assertequal(r8, 8, "r8") + assertequal(int(s8), 8, "s8") + var r9 int + var s9 float64 + r9, s9 = f9(1) + assertequal(r9, 9, "r9") + assertequal(int(s9), 9, "s9") + var t *T = new(T) + t.x = 1 + t.y = 2 + r10 := t.m10(1, 3.0) + assertequal(r10, 10, "10") +} diff --git a/platform/dbops/binaries/go/go/test/ken/shift.go b/platform/dbops/binaries/go/go/test/ken/shift.go new file mode 100644 index 0000000000000000000000000000000000000000..af8789615ee5ddc2197c7e845aad16631c88c3f3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/shift.go @@ -0,0 +1,121 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test shift. + +package main + +var ians [18]int; +var uans [18]uint; +var pass string; + +func +testi(i int, t1,t2,t3 int) { + n := ((t1*3) + t2)*2 + t3; + if i != ians[n] { + print("itest ", t1,t2,t3,pass, + " is ", i, " sb ", ians[n], "\n"); + } +} + +func +index(t1,t2,t3 int) int { + return ((t1*3) + t2)*2 + t3; +} + +func +testu(u uint, t1,t2,t3 int) { + n := index(t1,t2,t3); + if u != uans[n] { + print("utest ", t1,t2,t3,pass, + " is ", u, " sb ", uans[n], "\n"); + } +} + +func +main() { + var i int; + var u,c uint; + + /* + * test constant evaluations + */ + pass = "con"; // constant part + + testi( int(1234) << 0, 0,0,0); + testi( int(1234) >> 0, 0,0,1); + testi( int(1234) << 5, 0,1,0); + testi( int(1234) >> 5, 0,1,1); + + testi(int(-1234) << 0, 1,0,0); + testi(int(-1234) >> 0, 1,0,1); + testi(int(-1234) << 5, 1,1,0); + testi(int(-1234) >> 5, 1,1,1); + + testu(uint(5678) << 0, 2,0,0); + testu(uint(5678) >> 0, 2,0,1); + testu(uint(5678) << 5, 2,1,0); + testu(uint(5678) >> 5, 2,1,1); + + /* + * test variable evaluations + */ + pass = "var"; // variable part + + for t1:=0; t1<3; t1++ { // +int, -int, uint + for t2:=0; t2<3; t2++ { // 0, +small, +large + for t3:=0; t3<2; t3++ { // <<, >> + switch t1 { + case 0: i = 1234; + case 1: i = -1234; + case 2: u = 5678; + } + switch t2 { + case 0: c = 0; + case 1: c = 5; + case 2: c = 1025; + } + switch t3 { + case 0: i <<= c; u <<= c; + case 1: i >>= c; u >>= c; + } + switch t1 { + case 0: testi(i,t1,t2,t3); + case 1: testi(i,t1,t2,t3); + case 2: testu(u,t1,t2,t3); + } + } + } + } +} + +func +init() { + /* + * set the 'correct' answer + */ + + ians[index(0,0,0)] = 1234; + ians[index(0,0,1)] = 1234; + ians[index(0,1,0)] = 39488; + ians[index(0,1,1)] = 38; + ians[index(0,2,0)] = 0; + ians[index(0,2,1)] = 0; + + ians[index(1,0,0)] = -1234; + ians[index(1,0,1)] = -1234; + ians[index(1,1,0)] = -39488; + ians[index(1,1,1)] = -39; + ians[index(1,2,0)] = 0; + ians[index(1,2,1)] = -1; + + uans[index(2,0,0)] = 5678; + uans[index(2,0,1)] = 5678; + uans[index(2,1,0)] = 181696; + uans[index(2,1,1)] = 177; + uans[index(2,2,0)] = 0; + uans[index(2,2,1)] = 0; +} diff --git a/platform/dbops/binaries/go/go/test/ken/simparray.go b/platform/dbops/binaries/go/go/test/ken/simparray.go new file mode 100644 index 0000000000000000000000000000000000000000..0e81a341b8563d3506731199a7e128f57c583444 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simparray.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple operations on arrays. + +package main + +var b[10] float32; + +func +main() { + var a[10] float32; + + for i:=int16(5); i<10; i=i+1 { + a[i] = float32(i); + } + + s1 := float32(0); + for i:=5; i<10; i=i+1 { + s1 = s1 + a[i]; + } + + if s1 != 35 { panic(s1); } + + for i:=int16(5); i<10; i=i+1 { + b[i] = float32(i); + } + + s2 := float32(0); + for i:=5; i<10; i=i+1 { + s2 = s2 + b[i]; + } + + if s2 != 35 { panic(s2); } + + b := new([100]int); + for i:=0; i<100; i=i+1 { + b[i] = i; + } + + s3 := 0; + for i:=0; i<100; i=i+1 { + s3 = s3+b[i]; + } + + if s3 != 4950 { panic(s3); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/simpbool.go b/platform/dbops/binaries/go/go/test/ken/simpbool.go new file mode 100644 index 0000000000000000000000000000000000000000..ab2ecc21aad7603ebb3c9c3f85a34bc54a6ca993 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simpbool.go @@ -0,0 +1,107 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test basic operations on bool. + +package main + +type s struct { + a bool; + b bool; +} + +func +main() { + var a,b bool; + + a = true; + b = false; + + if !a { panic(1); } + if b { panic(2); } + if !!!a { panic(3); } + if !!b { panic(4); } + + a = !b; + if !a { panic(5); } + if !!!a { panic(6); } + + var x *s; + x = new(s); + x.a = true; + x.b = false; + + if !x.a { panic(7); } + if x.b { panic(8); } + if !!!x.a { panic(9); } + if !!x.b { panic(10); } + + x.a = !x.b; + if !x.a { panic(11); } + if !!!x.a { panic(12); } + + /* + * test && + */ + a = true; + b = true; + if !(a && b) { panic(21); } + if a && !b { panic(22); } + if !a && b { panic(23); } + if !a && !b { panic(24); } + + a = false; + b = true; + if !(!a && b) { panic(31); } + if !a && !b { panic(32); } + if a && b { panic(33); } + if a && !b { panic(34); } + + a = true; + b = false; + if !(a && !b) { panic(41); } + if a && b { panic(41); } + if !a && !b { panic(41); } + if !a && b { panic(44); } + + a = false; + b = false; + if !(!a && !b) { panic(51); } + if !a && b { panic(52); } + if a && !b { panic(53); } + if a && b { panic(54); } + + /* + * test || + */ + a = true; + b = true; + if !(a || b) { panic(61); } + if !(a || !b) { panic(62); } + if !(!a || b) { panic(63); } + if !a || !b { panic(64); } + + a = false; + b = true; + if !(!a || b) { panic(71); } + if !(!a || !b) { panic(72); } + if !(a || b) { panic(73); } + if a || !b { panic(74); } + + a = true; + b = false; + if !(a || !b) { panic(81); } + if !(a || b) { panic(82); } + if !(!a || !b) { panic(83); } + if !a || b { panic(84); } + + a = false; + b = false; + if !(!a || !b) { panic(91); } + if !(!a || b) { panic(92); } + if !(a || !b) { panic(93); } + if a || b { panic(94); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/simpconv.go b/platform/dbops/binaries/go/go/test/ken/simpconv.go new file mode 100644 index 0000000000000000000000000000000000000000..22cad2ad0e44a9808424d03edc18cba53aaff2db --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simpconv.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple arithmetic conversion. + +package main + +type vlong int64 +type short int16 + +func main() { + s1 := vlong(0) + for i := short(0); i < 10; i = i + 1 { + s1 = s1 + vlong(i) + } + if s1 != 45 { + panic(s1) + } + + s2 := float64(0) + for i := 0; i < 10; i = i + 1 { + s2 = s2 + float64(i) + } + if s2 != 45 { + panic(s2) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/simpfun.go b/platform/dbops/binaries/go/go/test/ken/simpfun.go new file mode 100644 index 0000000000000000000000000000000000000000..e5dc2b24955bfcc7a09163d383f183af1d6ba25a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simpfun.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple functions. + +package main + +func +main() { + var x int; + + x = fun(10,20,30); + if x != 60 { panic(x); } +} + +func +fun(ia,ib,ic int)int { + var o int; + + o = ia+ib+ic; + if o != 60 { panic(o); } + return o; +} diff --git a/platform/dbops/binaries/go/go/test/ken/simpswitch.go b/platform/dbops/binaries/go/go/test/ken/simpswitch.go new file mode 100644 index 0000000000000000000000000000000000000000..b28250b1d38132ebdd98ba6f1ce34c0c52e14be8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simpswitch.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test simple switch. + +package main + +func main() { + r := "" + a := 3 + for i := 0; i < 10; i = i + 1 { + switch i { + case 5: + r += "five" + case a, 7: + r += "a" + default: + r += string(i + '0') + } + r += "out" + string(i+'0') + } + if r != "0out01out12out2aout34out4fiveout56out6aout78out89out9" { + panic(r) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/simpvar.go b/platform/dbops/binaries/go/go/test/ken/simpvar.go new file mode 100644 index 0000000000000000000000000000000000000000..c6eefbb5addb431c485492917509c3569076ac90 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/simpvar.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test scoping of variables. + + +package main + +var x,y int; + +func +main() { + + x = 15; + y = 20; + { + var x int; + x = 25; + y = 25; + _ = x; + } + x = x+y; + if(x != 40) { panic(x); } +} diff --git a/platform/dbops/binaries/go/go/test/ken/slicearray.go b/platform/dbops/binaries/go/go/test/ken/slicearray.go new file mode 100644 index 0000000000000000000000000000000000000000..a431983d156b1852b2c83193c29d033bd95250eb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/slicearray.go @@ -0,0 +1,212 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test basic operations of slices and arrays. + +package main + +var bx [10]byte +var by []byte +var fx [10]float64 +var fy []float64 +var lb, hb int +var t int + +func main() { + lb = 0 + hb = 10 + by = bx[0:] + tstb() + + lb = 0 + hb = 10 + fy = fx[0:] + tstf() + + // width 1 (byte) + lb = 0 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[:hb] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:10] + tstb() + by = bx[0:] + tstb() + by = bx[:10] + tstb() + by = bx[:] + tstb() + + lb = 2 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:10] + tstb() + by = bx[2:] + tstb() + + lb = 0 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:8] + tstb() + by = bx[:8] + tstb() + by = bx[:hb] + tstb() + + lb = 2 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:8] + tstb() + + // width 8 (float64) + lb = 0 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:10] + tstf() + fy = fx[0:] + tstf() + fy = fx[:10] + tstf() + fy = fx[:] + tstf() + + lb = 2 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:10] + tstf() + fy = fx[2:] + tstf() + + lb = 0 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:8] + tstf() + fy = fx[:8] + tstf() + + lb = 2 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:8] + tstf() +} + +func tstb() { + t++ + if len(by) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(by), "hb-lb=", hb-lb) + panic("fail") + } + if cap(by) != len(bx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(by), "len(bx)-lb=", len(bx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if bx[i] != by[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "bx[", i, "]=", bx[i], + "by[", i-lb, "]=", by[i-lb]) + panic("fail") + } + } + by = nil +} + +func tstf() { + t++ + if len(fy) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(fy), "hb-lb=", hb-lb) + panic("fail") + } + if cap(fy) != len(fx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(fy), "len(fx)-lb=", len(fx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if fx[i] != fy[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "fx[", i, "]=", fx[i], + "fy[", i-lb, "]=", fy[i-lb]) + panic("fail") + } + } + fy = nil +} + +func init() { + for i := 0; i < len(bx); i++ { + bx[i] = byte(i + 20) + } + by = nil + + for i := 0; i < len(fx); i++ { + fx[i] = float64(i + 20) + } + fy = nil +} diff --git a/platform/dbops/binaries/go/go/test/ken/sliceslice.go b/platform/dbops/binaries/go/go/test/ken/sliceslice.go new file mode 100644 index 0000000000000000000000000000000000000000..c07c591252da9d69013a094df5715d1b1992f732 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/sliceslice.go @@ -0,0 +1,205 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test slicing and re-slicing. + +package main + +var bx []byte +var by []byte +var fx []float64 +var fy []float64 +var lb, hb int +var t int + +func main() { + + // width 1 (byte) + lb = 0 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[:hb] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:10] + tstb() + by = bx[0:] + tstb() + by = bx[:10] + tstb() + by = bx[:] + tstb() + + lb = 2 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:10] + tstb() + by = bx[2:] + tstb() + + lb = 0 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:8] + tstb() + by = bx[:8] + tstb() + by = bx[:hb] + tstb() + + lb = 2 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:8] + tstb() + + // width 4 (float64) + lb = 0 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:10] + tstf() + fy = fx[0:] + tstf() + fy = fx[:10] + tstf() + fy = fx[:] + tstf() + + lb = 2 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:10] + tstf() + fy = fx[2:] + tstf() + + lb = 0 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:8] + tstf() + fy = fx[:8] + tstf() + + lb = 2 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:8] + tstf() +} + +func tstb() { + t++ + if len(by) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(by), "hb-lb=", hb-lb) + panic("fail") + } + if cap(by) != len(bx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(by), "len(bx)-lb=", len(bx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if bx[i] != by[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "bx[", i, "]=", bx[i], + "by[", i-lb, "]=", by[i-lb]) + panic("fail") + } + } + by = nil +} + +func tstf() { + t++ + if len(fy) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(fy), "hb-lb=", hb-lb) + panic("fail") + } + if cap(fy) != len(fx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(fy), "len(fx)-lb=", len(fx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if fx[i] != fy[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "fx[", i, "]=", fx[i], + "fy[", i-lb, "]=", fy[i-lb]) + panic("fail") + } + } + fy = nil +} + +func init() { + bx = make([]byte, 10) + for i := 0; i < len(bx); i++ { + bx[i] = byte(i + 20) + } + by = nil + + fx = make([]float64, 10) + for i := 0; i < len(fx); i++ { + fx[i] = float64(i + 20) + } + fy = nil +} diff --git a/platform/dbops/binaries/go/go/test/ken/string.go b/platform/dbops/binaries/go/go/test/ken/string.go new file mode 100644 index 0000000000000000000000000000000000000000..7bb3cabbc2d12d58b3a8163007983af9b31c1067 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/string.go @@ -0,0 +1,114 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test string operations including printing. + +package main + +func main() { + var c string + + a := `abc` + b := `xyz` + + /* print a literal */ + print(`abc`) + + /* print a variable */ + print(b, "-") + + /* catenate literals */ + print(`abc`+`xyz`, "-") + + /* catenate variables */ + print(a+b, "-") + + /* compare literals */ + if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` { + panic("compare literals") + } + + /* compare variables */ + if a == b || a != a || a > b { + panic("compare variables") + } + + /* cat */ + c = a + b + print(c, "-") + + /* catequal */ + c = a + c += b + print(c, "-") + + /* clumsy evaluation */ + c = b + c = a + c + print(c, "-") + + /* len */ + if len(c) != 6 { + print("len ", len(c)) + panic("fail") + } + + /* index strings */ + for i := 0; i < len(c); i = i + 1 { + if c[i] != (a + b)[i] { + print("index ", i, " ", c[i], " ", (a + b)[i]) + panic("fail") + } + } + + /* slice strings */ + print(c[0:3], c[3:]) + + print("\n") + + /* create string with integer constant */ + c = string('x') + if c != "x" { + panic("create int " + c) + } + + /* create string with integer variable */ + v := 'x' + c = string(v) + if c != "x" { + panic("create int " + c) + } + + /* create string with byte array */ + var z1 [3]byte + z1[0] = 'a' + z1[1] = 'b' + z1[2] = 'c' + c = string(z1[0:]) + if c != "abc" { + panic("create byte array " + c) + } + + /* create string with int array */ + var z2 [3]rune + z2[0] = 'a' + z2[1] = '\u1234' + z2[2] = 'c' + c = string(z2[0:]) + if c != "a\u1234c" { + panic("create int array " + c) + } + + /* create string with byte array pointer */ + z3 := new([3]byte) + z3[0] = 'a' + z3[1] = 'b' + z3[2] = 'c' + c = string(z3[0:]) + if c != "abc" { + panic("create array pointer " + c) + } +} diff --git a/platform/dbops/binaries/go/go/test/ken/string.out b/platform/dbops/binaries/go/go/test/ken/string.out new file mode 100644 index 0000000000000000000000000000000000000000..8bc36bc6f531e791c1d1ac67428def37ded2ef7e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/string.out @@ -0,0 +1 @@ +abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz diff --git a/platform/dbops/binaries/go/go/test/ken/strvar.go b/platform/dbops/binaries/go/go/test/ken/strvar.go new file mode 100644 index 0000000000000000000000000000000000000000..4d511fe6735db22b1ebc46d8161d232157f8e154 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/ken/strvar.go @@ -0,0 +1,79 @@ +// run + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test struct-valued variables (not pointers). + +package main + +type x2 struct { a,b,c int; d int; }; +var g1 x2; +var g2 struct { a,b,c int; d x2; }; + +func +main() { + var x int; + var s1 *x2; + var s2 *struct { a,b,c int; d x2; }; + var s3 struct { a,b,c int; d x2; }; + + s1 = &g1; + s2 = &g2; + + s1.a = 1; + s1.b = 2; + s1.c = 3; + s1.d = 5; + + if(s1.c != 3) { panic(s1.c); } + if(g1.c != 3) { panic(g1.c); } + + s2.a = 7; + s2.b = 11; + s2.c = 13; + s2.d.a = 17; + s2.d.b = 19; + s2.d.c = 23; + s2.d.d = 29; + + if(s2.d.c != 23) { panic(s2.d.c); } + if(g2.d.c != 23) { panic(g2.d.c); } + + x = s1.a + + s1.b + + s1.c + + s1.d + + + s2.a + + s2.b + + s2.c + + s2.d.a + + s2.d.b + + s2.d.c + + s2.d.d; + + if(x != 130) { panic(x); } + + // test an automatic struct + s3.a = 7; + s3.b = 11; + s3.c = 13; + s3.d.a = 17; + s3.d.b = 19; + s3.d.c = 23; + s3.d.d = 29; + + if(s3.d.c != 23) { panic(s3.d.c); } + + x = s3.a + + s3.b + + s3.c + + s3.d.a + + s3.d.b + + s3.d.c + + s3.d.d; + + if(x != 119) { panic(x); } +} diff --git a/platform/dbops/binaries/go/go/test/linkname.dir/linkname1.go b/platform/dbops/binaries/go/go/test/linkname.dir/linkname1.go new file mode 100644 index 0000000000000000000000000000000000000000..7d51b94802841f23e34e989dff025f538d15e124 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/linkname.dir/linkname1.go @@ -0,0 +1,10 @@ +package x + +func indexByte(xs []byte, b byte) int { // ERROR "xs does not escape" "can inline indexByte" + for i, x := range xs { + if x == b { + return i + } + } + return -1 +} diff --git a/platform/dbops/binaries/go/go/test/linkname.dir/linkname2.go b/platform/dbops/binaries/go/go/test/linkname.dir/linkname2.go new file mode 100644 index 0000000000000000000000000000000000000000..d2ee841624b5995ac7f99c778ae0e60195715f93 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/linkname.dir/linkname2.go @@ -0,0 +1,13 @@ +package y + +import _ "unsafe" + +//go:linkname byteIndex test/linkname1.indexByte +func byteIndex(xs []byte, b byte) int // ERROR "leaking param: xs" + +func ContainsSlash(data []byte) bool { // ERROR "leaking param: data" "can inline ContainsSlash" + if byteIndex(data, '/') != -1 { + return true + } + return false +} diff --git a/platform/dbops/binaries/go/go/test/linkname.dir/linkname3.go b/platform/dbops/binaries/go/go/test/linkname.dir/linkname3.go new file mode 100644 index 0000000000000000000000000000000000000000..cbbd3a10ba2baf8a82744bc7ecfbfcb559d7affd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/linkname.dir/linkname3.go @@ -0,0 +1,11 @@ +package main + +import _ "./linkname1" +import "./linkname2" + +func main() { // ERROR "can inline main" + str := "hello/world" + bs := []byte(str) // ERROR "\(\[\]byte\)\(str\) escapes to heap" + if y.ContainsSlash(bs) { // ERROR "inlining call to y.ContainsSlash" + } +} diff --git a/platform/dbops/binaries/go/go/test/method4.dir/method4a.go b/platform/dbops/binaries/go/go/test/method4.dir/method4a.go new file mode 100644 index 0000000000000000000000000000000000000000..a7df04cec366f68e6cd6ab59d38367e41ab85148 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/method4.dir/method4a.go @@ -0,0 +1,37 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test method expressions with arguments. + +package method4a + +type T1 int + +type T2 struct { + F int +} + +type I1 interface { + Sum([]int, int) int +} + +type I2 interface { + Sum(a []int, b int) int +} + +func (i T1) Sum(a []int, b int) int { + r := int(i) + b + for _, v := range a { + r += v + } + return r +} + +func (p *T2) Sum(a []int, b int) int { + r := p.F + b + for _, v := range a { + r += v + } + return r +} diff --git a/platform/dbops/binaries/go/go/test/method4.dir/prog.go b/platform/dbops/binaries/go/go/test/method4.dir/prog.go new file mode 100644 index 0000000000000000000000000000000000000000..cb5cf65f2904f31ad2dd251cabaff24462f0cae9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/method4.dir/prog.go @@ -0,0 +1,111 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test method expressions with arguments. + +package main + +import "./method4a" + +type T1 int + +type T2 struct { + f int +} + +type I1 interface { + Sum([]int, int) int +} + +type I2 interface { + Sum(a []int, b int) int +} + +func (i T1) Sum(a []int, b int) int { + r := int(i) + b + for _, v := range a { + r += v + } + return r +} + +func (p *T2) Sum(a []int, b int) int { + r := p.f + b + for _, v := range a { + r += v + } + return r +} + +func eq(v1, v2 int) { + if v1 != v2 { + panic(0) + } +} + +func main() { + a := []int{1, 2, 3} + t1 := T1(4) + t2 := &T2{4} + + eq(t1.Sum(a, 5), 15) + eq(t2.Sum(a, 6), 16) + + eq(T1.Sum(t1, a, 7), 17) + eq((*T2).Sum(t2, a, 8), 18) + + f1 := T1.Sum + eq(f1(t1, a, 9), 19) + f2 := (*T2).Sum + eq(f2(t2, a, 10), 20) + + eq(I1.Sum(t1, a, 11), 21) + eq(I1.Sum(t2, a, 12), 22) + + f3 := I1.Sum + eq(f3(t1, a, 13), 23) + eq(f3(t2, a, 14), 24) + + eq(I2.Sum(t1, a, 15), 25) + eq(I2.Sum(t2, a, 16), 26) + + f4 := I2.Sum + eq(f4(t1, a, 17), 27) + eq(f4(t2, a, 18), 28) + + // issue 6723 + f5 := (interface { + I2 + }).Sum + eq(f5(t1, a, 19), 29) + eq(f5(t2, a, 20), 30) + + mt1 := method4a.T1(4) + mt2 := &method4a.T2{4} + + eq(mt1.Sum(a, 30), 40) + eq(mt2.Sum(a, 31), 41) + + eq(method4a.T1.Sum(mt1, a, 32), 42) + eq((*method4a.T2).Sum(mt2, a, 33), 43) + + g1 := method4a.T1.Sum + eq(g1(mt1, a, 34), 44) + g2 := (*method4a.T2).Sum + eq(g2(mt2, a, 35), 45) + + eq(method4a.I1.Sum(mt1, a, 36), 46) + eq(method4a.I1.Sum(mt2, a, 37), 47) + + g3 := method4a.I1.Sum + eq(g3(mt1, a, 38), 48) + eq(g3(mt2, a, 39), 49) + + eq(method4a.I2.Sum(mt1, a, 40), 50) + eq(method4a.I2.Sum(mt2, a, 41), 51) + + g4 := method4a.I2.Sum + eq(g4(mt1, a, 42), 52) + eq(g4(mt2, a, 43), 53) +} diff --git a/platform/dbops/binaries/go/go/test/retjmp.dir/a.s b/platform/dbops/binaries/go/go/test/retjmp.dir/a.s new file mode 100644 index 0000000000000000000000000000000000000000..101b3428fc2d6c794b2119fffe709e58a74c910b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/retjmp.dir/a.s @@ -0,0 +1,16 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +TEXT ·f(SB), 4, $8-0 + CALL ·f1(SB) + RET ·f2(SB) + CALL ·unreachable(SB) + +TEXT ·leaf(SB), 4, $0-0 + RET ·f3(SB) + JMP ·unreachable(SB) + +TEXT ·leaf2(SB), 4, $32-0 // nonzero frame size + RET ·f4(SB) + JMP ·unreachable(SB) diff --git a/platform/dbops/binaries/go/go/test/retjmp.dir/main.go b/platform/dbops/binaries/go/go/test/retjmp.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..0bed5a61b7ac623be289e969c8f17f7b7b9b44c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/retjmp.dir/main.go @@ -0,0 +1,38 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f() +func leaf() +func leaf2() + +var f1called, f2called, f3called, f4called bool + +func main() { + f() + if !f1called { + panic("f1 not called") + } + if !f2called { + panic("f2 not called") + } + leaf() + if !f3called { + panic("f3 not called") + } + leaf2() + if !f4called { + panic("f4 not called") + } +} + +func f1() { f1called = true } +func f2() { f2called = true } +func f3() { f3called = true } +func f4() { f4called = true } + +func unreachable() { + panic("unreachable function called") +} diff --git a/platform/dbops/binaries/go/go/test/runtime/README b/platform/dbops/binaries/go/go/test/runtime/README new file mode 100644 index 0000000000000000000000000000000000000000..249031afc1827494da8e1dbde3ee06451308c5b1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/runtime/README @@ -0,0 +1,7 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +The runtime directory contains tests that specifically need +to be compiled as-if in the runtime package. For error-check +tests, these require the additional flags -+ and -p=runtime. diff --git a/platform/dbops/binaries/go/go/test/runtime/inlinegcpc.go b/platform/dbops/binaries/go/go/test/runtime/inlinegcpc.go new file mode 100644 index 0000000000000000000000000000000000000000..c423993b713428c888f76ae6281724dd99dd6a01 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/runtime/inlinegcpc.go @@ -0,0 +1,29 @@ +// errorcheck -0 -+ -p=runtime -m + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +// A function that calls runtime.getcallerpc or runtime.getcallersp() +// cannot be inlined, no matter how small it is. + +func getcallerpc() uintptr +func getcallersp() uintptr + +func pc() uintptr { + return getcallerpc() + 1 +} + +func cpc() uintptr { // ERROR "can inline cpc" + return pc() + 2 +} + +func sp() uintptr { + return getcallersp() + 3 +} + +func csp() uintptr { // ERROR "can inline csp" + return sp() + 4 +} diff --git a/platform/dbops/binaries/go/go/test/stress/maps.go b/platform/dbops/binaries/go/go/test/stress/maps.go new file mode 100644 index 0000000000000000000000000000000000000000..8ada23a9806bfa1a7704f44b25a639161df55e0b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/stress/maps.go @@ -0,0 +1,113 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "math/rand" + "runtime" + "sync" +) + +func mapTypes() []MapType { + // TODO(bradfitz): bunch more map types of all different key and value types. + // Use reflect.MapOf and a program to generate lots of types & struct types. + // For now, just one: + return []MapType{intMapType{}} +} + +type MapType interface { + NewMap() Map +} + +type Map interface { + AddItem() + DelItem() + Len() int + GetItem() + RangeAll() +} + +func stressMapType(mt MapType, done func()) { + defer done() + m := mt.NewMap() + for m.Len() < 10000 { + Println("map at ", m.Len()) + if m.Len()%100 == 0 { + runtime.Gosched() + } + m.AddItem() + m.AddItem() + m.DelItem() + var wg sync.WaitGroup + const numGets = 10 + wg.Add(numGets) + for i := 0; i < numGets; i++ { + go func(i int) { + if i&1 == 0 { + m.GetItem() + } else { + m.RangeAll() + } + wg.Done() + }(i) + } + wg.Wait() + } + for m.Len() > 0 { + m.DelItem() + } +} + +type intMapType struct{} + +func (intMapType) NewMap() Map { + return make(intMap) +} + +var deadcafe = []byte("\xDE\xAD\xCA\xFE") + +type intMap map[int][]byte + +func (m intMap) AddItem() { + s0 := len(m) + for len(m) == s0 { + key := rand.Intn(s0 + 1) + m[key] = make([]byte, rand.Intn(64<<10)) + } +} + +func (m intMap) DelItem() { + for k := range m { + delete(m, k) + return + } +} + +func (m intMap) GetItem() { + key := rand.Intn(len(m)) + if s, ok := m[key]; ok { + copy(s, deadcafe) + } +} + +func (m intMap) Len() int { return len(m) } + +func (m intMap) RangeAll() { + for _ = range m { + } + for range m { + } +} + +func stressMaps() { + for { + var wg sync.WaitGroup + for _, mt := range mapTypes() { + wg.Add(1) + go stressMapType(mt, wg.Done) + } + wg.Wait() + } +} diff --git a/platform/dbops/binaries/go/go/test/stress/parsego.go b/platform/dbops/binaries/go/go/test/stress/parsego.go new file mode 100644 index 0000000000000000000000000000000000000000..98c4d9ad1bca7f94151096d5b7048abbebbc1463 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/stress/parsego.go @@ -0,0 +1,220 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "go/ast" + "go/parser" + "go/token" + "os" + "path" + "runtime" + "strings" +) + +func isGoFile(dir os.FileInfo) bool { + return !dir.IsDir() && + !strings.HasPrefix(dir.Name(), ".") && // ignore .files + path.Ext(dir.Name()) == ".go" +} + +func isPkgFile(dir os.FileInfo) bool { + return isGoFile(dir) && + !strings.HasSuffix(dir.Name(), "_test.go") // ignore test files +} + +func pkgName(filename string) string { + file, err := parser.ParseFile(token.NewFileSet(), filename, nil, parser.PackageClauseOnly) + if err != nil || file == nil { + return "" + } + return file.Name.Name +} + +func parseDir(dirpath string) map[string]*ast.Package { + // the package name is the directory name within its parent. + // (use dirname instead of path because dirname is clean; it + // has no trailing '/') + _, pkgname := path.Split(dirpath) + + // filter function to select the desired .go files + filter := func(d os.FileInfo) bool { + if isPkgFile(d) { + // Some directories contain main packages: Only accept + // files that belong to the expected package so that + // parser.ParsePackage doesn't return "multiple packages + // found" errors. + // Additionally, accept the special package name + // fakePkgName if we are looking at cmd documentation. + name := pkgName(dirpath + "/" + d.Name()) + return name == pkgname + } + return false + } + + // get package AST + pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments) + if err != nil { + println("parse", dirpath, err.Error()) + panic("go ParseDir fail: " + err.Error()) + } + return pkgs +} + +func stressParseGo() { + pkgroot := runtime.GOROOT() + "/src/" + for { + m := make(map[string]map[string]*ast.Package) + for _, pkg := range packages { + m[pkg] = parseDir(pkgroot + pkg) + Println("parsed go package", pkg) + } + } +} + +// find . -type d -not -path "./exp" -not -path "./exp/*" -printf "\t\"%p\",\n" | sort | sed "s/\.\///" | grep -v testdata +var packages = []string{ + "archive", + "archive/tar", + "archive/zip", + "bufio", + "builtin", + "bytes", + "compress", + "compress/bzip2", + "compress/flate", + "compress/gzip", + "compress/lzw", + "compress/zlib", + "container", + "container/heap", + "container/list", + "container/ring", + "crypto", + "crypto/aes", + "crypto/cipher", + "crypto/des", + "crypto/dsa", + "crypto/ecdsa", + "crypto/elliptic", + "crypto/hmac", + "crypto/md5", + "crypto/rand", + "crypto/rc4", + "crypto/rsa", + "crypto/sha1", + "crypto/sha256", + "crypto/sha512", + "crypto/subtle", + "crypto/tls", + "crypto/x509", + "crypto/x509/pkix", + "database", + "database/sql", + "database/sql/driver", + "debug", + "debug/dwarf", + "debug/elf", + "debug/gosym", + "debug/macho", + "debug/pe", + "encoding", + "encoding/ascii85", + "encoding/asn1", + "encoding/base32", + "encoding/base64", + "encoding/binary", + "encoding/csv", + "encoding/gob", + "encoding/hex", + "encoding/json", + "encoding/pem", + "encoding/xml", + "errors", + "expvar", + "flag", + "fmt", + "go", + "go/ast", + "go/build", + "go/doc", + "go/format", + "go/parser", + "go/printer", + "go/scanner", + "go/token", + "hash", + "hash/adler32", + "hash/crc32", + "hash/crc64", + "hash/fnv", + "html", + "html/template", + "image", + "image/color", + "image/draw", + "image/gif", + "image/jpeg", + "image/png", + "index", + "index/suffixarray", + "io", + "io/ioutil", + "log", + "log/syslog", + "math", + "math/big", + "math/cmplx", + "math/rand", + "mime", + "mime/multipart", + "net", + "net/http", + "net/http/cgi", + "net/http/cookiejar", + "net/http/fcgi", + "net/http/httptest", + "net/http/httputil", + "net/http/pprof", + "net/mail", + "net/rpc", + "net/rpc/jsonrpc", + "net/smtp", + "net/textproto", + "net/url", + "os", + "os/exec", + "os/signal", + "os/user", + "path", + "path/filepath", + "reflect", + "regexp", + "regexp/syntax", + "runtime", + "runtime/cgo", + "runtime/debug", + "runtime/pprof", + "runtime/race", + "sort", + "strconv", + "strings", + "sync", + "sync/atomic", + "syscall", + "testing", + "testing/iotest", + "testing/quick", + "text", + "text/scanner", + "text/tabwriter", + "text/template", + "text/template/parse", + "time", + "unicode", + "unicode/utf16", + "unicode/utf8", + "unsafe", +} diff --git a/platform/dbops/binaries/go/go/test/stress/runstress.go b/platform/dbops/binaries/go/go/test/stress/runstress.go new file mode 100644 index 0000000000000000000000000000000000000000..b752fa8dbbc31f554170d1df140051cdaf9844e5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/stress/runstress.go @@ -0,0 +1,168 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The runstress tool stresses the runtime. +// +// It runs forever and should never fail. It tries to stress the garbage collector, +// maps, channels, the network, and everything else provided by the runtime. +package main + +import ( + "flag" + "fmt" + "io" + "log" + "math/rand" + "net" + "net/http" + "net/http/httptest" + "os/exec" + "strconv" + "time" +) + +var ( + v = flag.Bool("v", false, "verbose") + doMaps = flag.Bool("maps", true, "stress maps") + doExec = flag.Bool("exec", true, "stress exec") + doChan = flag.Bool("chan", true, "stress channels") + doNet = flag.Bool("net", true, "stress networking") + doParseGo = flag.Bool("parsego", true, "stress parsing Go (generates garbage)") +) + +func Println(a ...interface{}) { + if *v { + log.Println(a...) + } +} + +func dialStress(a net.Addr) { + for { + d := net.Dialer{Timeout: time.Duration(rand.Intn(1e9))} + c, err := d.Dial("tcp", a.String()) + if err == nil { + Println("did dial") + go func() { + time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond) + c.Close() + Println("closed dial") + }() + } + // Don't run out of ephermeral ports too quickly: + time.Sleep(250 * time.Millisecond) + } +} + +func stressNet() { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + size, _ := strconv.Atoi(r.FormValue("size")) + w.Write(make([]byte, size)) + })) + go dialStress(ts.Listener.Addr()) + for { + size := rand.Intn(128 << 10) + res, err := http.Get(fmt.Sprintf("%s/?size=%d", ts.URL, size)) + if err != nil { + log.Fatalf("stressNet: http Get error: %v", err) + } + if res.StatusCode != 200 { + log.Fatalf("stressNet: Status code = %d", res.StatusCode) + } + n, err := io.Copy(io.Discard, res.Body) + if err != nil { + log.Fatalf("stressNet: io.Copy: %v", err) + } + if n != int64(size) { + log.Fatalf("stressNet: copied = %d; want %d", n, size) + } + res.Body.Close() + Println("did http", size) + } +} + +func doAnExec() { + exit := rand.Intn(2) + wantOutput := fmt.Sprintf("output-%d", rand.Intn(1e9)) + cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("echo %s; exit %d", wantOutput, exit)) + out, err := cmd.CombinedOutput() + if exit == 1 { + if err == nil { + log.Fatal("stressExec: unexpected exec success") + } + return + } + if err != nil { + log.Fatalf("stressExec: exec failure: %v: %s", err, out) + } + wantOutput += "\n" + if string(out) != wantOutput { + log.Fatalf("stressExec: exec output = %q; want %q", out, wantOutput) + } + Println("did exec") +} + +func stressExec() { + gate := make(chan bool, 10) // max execs at once + for { + gate <- true + go func() { + doAnExec() + <-gate + }() + } +} + +func ringf(in <-chan int, out chan<- int, donec chan bool) { + for { + var n int + select { + case <-donec: + return + case n = <-in: + } + if n == 0 { + close(donec) + return + } + out <- n - 1 + } +} + +func threadRing(bufsize int) { + const N = 100 + donec := make(chan bool) + one := make(chan int, bufsize) // will be input to thread 1 + var in, out chan int = nil, one + for i := 1; i <= N-1; i++ { + in, out = out, make(chan int, bufsize) + go ringf(in, out, donec) + } + go ringf(out, one, donec) + one <- N + <-donec + Println("did threadring of", bufsize) +} + +func stressChannels() { + for { + threadRing(0) + threadRing(1) + } +} + +func main() { + flag.Parse() + for want, f := range map[*bool]func(){ + doMaps: stressMaps, + doNet: stressNet, + doExec: stressExec, + doChan: stressChannels, + doParseGo: stressParseGo, + } { + if *want { + go f() + } + } + select {} +} diff --git a/platform/dbops/binaries/go/go/test/syntax/chan.go b/platform/dbops/binaries/go/go/test/syntax/chan.go new file mode 100644 index 0000000000000000000000000000000000000000..6f9d77df9091d48605b9e9f640c1c75bb49bdaf8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/chan.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type xyz struct { + ch chan +} // ERROR "unexpected .*}.* in channel type|missing channel element type" + +func Foo(y chan) { // ERROR "unexpected .*\).* in channel type|missing channel element type" +} + +func Bar(x chan, y int) { // ERROR "unexpected comma in channel type|missing channel element type" +} diff --git a/platform/dbops/binaries/go/go/test/syntax/chan1.go b/platform/dbops/binaries/go/go/test/syntax/chan1.go new file mode 100644 index 0000000000000000000000000000000000000000..88a5b4777b8e8d5b3cacf3945a8b4371f6a0bf1a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/chan1.go @@ -0,0 +1,17 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var c chan int +var v int + +func main() { + if c <- v { // ERROR "cannot use c <- v as value|send statement used as value" + } +} + +var _ = c <- v // ERROR "unexpected <-|send statement used as value" diff --git a/platform/dbops/binaries/go/go/test/syntax/composite.go b/platform/dbops/binaries/go/go/test/syntax/composite.go new file mode 100644 index 0000000000000000000000000000000000000000..b4e03f3167a54342b254e45389584a34d89af464 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/composite.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var a = []int{ + 3 // ERROR "need trailing comma before newline in composite literal|possibly missing comma or }" +} diff --git a/platform/dbops/binaries/go/go/test/syntax/ddd.go b/platform/dbops/binaries/go/go/test/syntax/ddd.go new file mode 100644 index 0000000000000000000000000000000000000000..8d1e4d19035dcc06792c0ed9f49b878d7c5ad31f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/ddd.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f() { + g(f..3) // ERROR "unexpected literal \.3, expected name or \(" +} diff --git a/platform/dbops/binaries/go/go/test/syntax/else.go b/platform/dbops/binaries/go/go/test/syntax/else.go new file mode 100644 index 0000000000000000000000000000000000000000..953732907156ec141621373c34d71880a0444334 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/else.go @@ -0,0 +1,12 @@ +// errorcheck + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if true { + } else ; // ERROR "else must be followed by if or statement block|expected .if. or .{." +} diff --git a/platform/dbops/binaries/go/go/test/syntax/if.go b/platform/dbops/binaries/go/go/test/syntax/if.go new file mode 100644 index 0000000000000000000000000000000000000000..c208a9f1360829bc82244783e8053333dce28ce5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/if.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func x() { +} + +func main() { + if { // ERROR "missing condition" + } + + if x(); { // ERROR "missing condition" + } +} diff --git a/platform/dbops/binaries/go/go/test/syntax/import.go b/platform/dbops/binaries/go/go/test/syntax/import.go new file mode 100644 index 0000000000000000000000000000000000000000..8010beddf874cac071b5a14cc88df07b1983184d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/import.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "io", // ERROR "unexpected comma" + "os" +) + + diff --git a/platform/dbops/binaries/go/go/test/syntax/initvar.go b/platform/dbops/binaries/go/go/test/syntax/initvar.go new file mode 100644 index 0000000000000000000000000000000000000000..74623f587c57b1f997ef2b1614359b561398e8a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/initvar.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if var x = 0; x < 10 {} // ERROR "var declaration not allowed in if initializer" + + switch var x = 0; x {} // ERROR "var declaration not allowed in switch initializer" + + for var x = 0; x < 10; {} // ERROR "var declaration not allowed in for initializer" +} diff --git a/platform/dbops/binaries/go/go/test/syntax/semi1.go b/platform/dbops/binaries/go/go/test/syntax/semi1.go new file mode 100644 index 0000000000000000000000000000000000000000..8eed05c1ca105417f5ebf26291b00f5bb6158bf0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi1.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if x; y // ERROR "expected .*{.* after if clause|undefined" + { + z // GCCGO_ERROR "undefined" + + diff --git a/platform/dbops/binaries/go/go/test/syntax/semi2.go b/platform/dbops/binaries/go/go/test/syntax/semi2.go new file mode 100644 index 0000000000000000000000000000000000000000..921678999a1dab0eb58b44ee3f2547aaeef46c76 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi2.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + switch x; y // ERROR "missing .*{.* after switch clause|undefined" + { + z + + diff --git a/platform/dbops/binaries/go/go/test/syntax/semi3.go b/platform/dbops/binaries/go/go/test/syntax/semi3.go new file mode 100644 index 0000000000000000000000000000000000000000..d064ce631c946587b441ad1471ed0f174f81a8f4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi3.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for x; y; z // ERROR "expected .*{.* after for clause|undefined" + { + z // GCCGO_ERROR "undefined" + + diff --git a/platform/dbops/binaries/go/go/test/syntax/semi4.go b/platform/dbops/binaries/go/go/test/syntax/semi4.go new file mode 100644 index 0000000000000000000000000000000000000000..62a511e6104e47ce0835417c7a452b71226b2c59 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi4.go @@ -0,0 +1,12 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for x // GCCGO_ERROR "undefined" + { // ERROR "unexpected {, expected for loop condition|expecting .*{.* after for clause" + z // GCCGO_ERROR "undefined" diff --git a/platform/dbops/binaries/go/go/test/syntax/semi5.go b/platform/dbops/binaries/go/go/test/syntax/semi5.go new file mode 100644 index 0000000000000000000000000000000000000000..c54a994d9f0bf135fc7e22f5df9996f590a92bf5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi5.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() +{ // ERROR "unexpected semicolon or newline before .?{.?" + + + diff --git a/platform/dbops/binaries/go/go/test/syntax/semi6.go b/platform/dbops/binaries/go/go/test/syntax/semi6.go new file mode 100644 index 0000000000000000000000000000000000000000..9bc730d43d656a2e659a7511b31696f27c72fb34 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi6.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T1 // ERROR "newline in type declaration" + +type T2 /* // ERROR "(semicolon.*|EOF) in type declaration" */ \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/syntax/semi7.go b/platform/dbops/binaries/go/go/test/syntax/semi7.go new file mode 100644 index 0000000000000000000000000000000000000000..a1948b0f7d38b6ed93aef91ccc1cc1fd60bed20b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/semi7.go @@ -0,0 +1,14 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if x { } // GCCGO_ERROR "undefined" + else { } // ERROR "unexpected semicolon or newline before .?else.?|unexpected else" +} + + diff --git a/platform/dbops/binaries/go/go/test/syntax/topexpr.go b/platform/dbops/binaries/go/go/test/syntax/topexpr.go new file mode 100644 index 0000000000000000000000000000000000000000..be080d20e53d85739dfea27d286048fcf37ad833 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/topexpr.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +fmt.Printf("hello") // ERROR "non-declaration statement outside function body|expected declaration" + +func main() { +} + +x++ // ERROR "non-declaration statement outside function body|expected declaration" + +func init() { +} + +x,y := 1, 2 // ERROR "non-declaration statement outside function body|expected declaration" + diff --git a/platform/dbops/binaries/go/go/test/syntax/typesw.go b/platform/dbops/binaries/go/go/test/syntax/typesw.go new file mode 100644 index 0000000000000000000000000000000000000000..378193397897e5755d78d8f3cac2426fba8aa02d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/typesw.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + switch main() := interface{}(nil).(type) { // ERROR "invalid variable name|cannot use .* as value" + default: + } +} diff --git a/platform/dbops/binaries/go/go/test/syntax/vareq.go b/platform/dbops/binaries/go/go/test/syntax/vareq.go new file mode 100644 index 0000000000000000000000000000000000000000..0d4bb78b8fb695d6e648368de81cfc520fb9075a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/vareq.go @@ -0,0 +1,10 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or '}' or newline" diff --git a/platform/dbops/binaries/go/go/test/syntax/vareq1.go b/platform/dbops/binaries/go/go/test/syntax/vareq1.go new file mode 100644 index 0000000000000000000000000000000000000000..a2f9f34d33c6f10f77fc78851e9b8774452321bc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/syntax/vareq1.go @@ -0,0 +1,10 @@ +// errorcheck + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|unexpected { after top level declaration|expected ';' or newline after top level declaration" + diff --git a/platform/dbops/binaries/go/go/test/typeparam/absdiff.go b/platform/dbops/binaries/go/go/test/typeparam/absdiff.go new file mode 100644 index 0000000000000000000000000000000000000000..9c83effbda4f2b6b8f0fd8d89004a86f4db9c19e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/absdiff.go @@ -0,0 +1,94 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Numeric interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~complex64 | ~complex128 +} + +// numericAbs matches numeric types with an Abs method. +type numericAbs[T any] interface { + Numeric + Abs() T +} + +// AbsDifference computes the absolute value of the difference of +// a and b, where the absolute value is determined by the Abs method. +func absDifference[T numericAbs[T]](a, b T) T { + d := a - b + return d.Abs() +} + +// orderedNumeric matches numeric types that support the < operator. +type orderedNumeric interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 +} + +// Complex matches the two complex types, which do not have a < operator. +type Complex interface { + ~complex64 | ~complex128 +} + +// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). +// // orderedAbs is a helper type that defines an Abs method for +// // ordered numeric types. +// type orderedAbs[T orderedNumeric] T +// +// func (a orderedAbs[T]) Abs() orderedAbs[T] { +// if a < 0 { +// return -a +// } +// return a +// } +// +// // complexAbs is a helper type that defines an Abs method for +// // complex types. +// type complexAbs[T Complex] T +// +// func (a complexAbs[T]) Abs() complexAbs[T] { +// r := float64(real(a)) +// i := float64(imag(a)) +// d := math.Sqrt(r*r + i*i) +// return complexAbs[T](complex(d, 0)) +// } +// +// // OrderedAbsDifference returns the absolute value of the difference +// // between a and b, where a and b are of an ordered type. +// func orderedAbsDifference[T orderedNumeric](a, b T) T { +// return T(absDifference(orderedAbs[T](a), orderedAbs[T](b))) +// } +// +// // ComplexAbsDifference returns the absolute value of the difference +// // between a and b, where a and b are of a complex type. +// func complexAbsDifference[T Complex](a, b T) T { +// return T(absDifference(complexAbs[T](a), complexAbs[T](b))) +// } + +func main() { + // // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). + // if got, want := orderedAbsDifference(1.0, -2.0), 3.0; got != want { + // panic(fmt.Sprintf("got = %v, want = %v", got, want)) + // } + // if got, want := orderedAbsDifference(-1.0, 2.0), 3.0; got != want { + // panic(fmt.Sprintf("got = %v, want = %v", got, want)) + // } + // if got, want := orderedAbsDifference(-20, 15), 35; got != want { + // panic(fmt.Sprintf("got = %v, want = %v", got, want)) + // } + // + // if got, want := complexAbsDifference(5.0+2.0i, 2.0-2.0i), 5+0i; got != want { + // panic(fmt.Sprintf("got = %v, want = %v", got, want)) + // } + // if got, want := complexAbsDifference(2.0-2.0i, 5.0+2.0i), 5+0i; got != want { + // panic(fmt.Sprintf("got = %v, want = %v", got, want)) + // } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/absdiff2.go b/platform/dbops/binaries/go/go/test/typeparam/absdiff2.go new file mode 100644 index 0000000000000000000000000000000000000000..87a1ec6de1aa6c1224e9cb08f2f6112cde14ad42 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/absdiff2.go @@ -0,0 +1,135 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// absdiff example in which an Abs method is attached to a generic type, which is a +// structure with a single field that may be a list of possible basic types. + +package main + +import ( + "fmt" + "math" +) + +type Numeric interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~complex64 | ~complex128 +} + +// numericAbs matches a struct containing a numeric type that has an Abs method. +type numericAbs[T Numeric] interface { + ~struct{ Value_ T } + Abs() T + Value() T +} + +// absDifference computes the absolute value of the difference of +// a and b, where the absolute value is determined by the Abs method. +func absDifference[T Numeric, U numericAbs[T]](a, b U) T { + d := a.Value() - b.Value() + dt := U{Value_: d} + return dt.Abs() +} + +// orderedNumeric matches numeric types that support the < operator. +type orderedNumeric interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 +} + +// Complex matches the two complex types, which do not have a < operator. +type Complex interface { + ~complex64 | ~complex128 +} + +// orderedAbs is a helper type that defines an Abs method for +// a struct containing an ordered numeric type. +type orderedAbs[T orderedNumeric] struct { + Value_ T +} + +func (a orderedAbs[T]) Abs() T { + if a.Value_ < 0 { + return -a.Value_ + } + return a.Value_ +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (a orderedAbs[T]) Value() T { + return a.Value_ +} + +// complexAbs is a helper type that defines an Abs method for +// a struct containing a complex type. +type complexAbs[T Complex] struct { + Value_ T +} + +func realimag(x any) (re, im float64) { + switch z := x.(type) { + case complex64: + re = float64(real(z)) + im = float64(imag(z)) + case complex128: + re = real(z) + im = imag(z) + default: + panic("unknown complex type") + } + return +} + +func (a complexAbs[T]) Abs() T { + // TODO use direct conversion instead of realimag once #50937 is fixed + r, i := realimag(a.Value_) + // r := float64(real(a.Value)) + // i := float64(imag(a.Value)) + d := math.Sqrt(r*r + i*i) + return T(complex(d, 0)) +} + +func (a complexAbs[T]) Value() T { + return a.Value_ +} + +// OrderedAbsDifference returns the absolute value of the difference +// between a and b, where a and b are of an ordered type. +func OrderedAbsDifference[T orderedNumeric](a, b T) T { + return absDifference(orderedAbs[T]{a}, orderedAbs[T]{b}) +} + +// ComplexAbsDifference returns the absolute value of the difference +// between a and b, where a and b are of a complex type. +func ComplexAbsDifference[T Complex](a, b T) T { + return absDifference(complexAbs[T]{a}, complexAbs[T]{b}) +} + +func main() { + if got, want := OrderedAbsDifference(1.0, -2.0), 3.0; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := OrderedAbsDifference(-1.0, 2.0), 3.0; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := OrderedAbsDifference(-20, 15), 35; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + + if got, want := ComplexAbsDifference(5.0+2.0i, 2.0-2.0i), 5+0i; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := ComplexAbsDifference(2.0-2.0i, 5.0+2.0i), 5+0i; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/absdiff3.go b/platform/dbops/binaries/go/go/test/typeparam/absdiff3.go new file mode 100644 index 0000000000000000000000000000000000000000..c85cd1d6a552ececf30c865f67c4d789891d72f1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/absdiff3.go @@ -0,0 +1,98 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// absdiff example using a function argument rather than attaching an +// Abs method to a structure containing base types. + +package main + +import ( + "fmt" + "math" +) + +type Numeric interface { + OrderedNumeric | Complex +} + +// absDifference computes the absolute value of the difference of +// a and b, where the absolute value is determined by the abs function. +func absDifference[T Numeric](a, b T, abs func(a T) T) T { + return abs(a - b) +} + +// OrderedNumeric matches numeric types that support the < operator. +type OrderedNumeric interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 +} + +func Abs[T OrderedNumeric](a T) T { + if a < 0 { + return -a + } + return a +} + +// Complex matches the two complex types, which do not have a < operator. +type Complex interface { + ~complex64 | ~complex128 +} + +func realimag(x any) (re, im float64) { + switch z := x.(type) { + case complex64: + re = float64(real(z)) + im = float64(imag(z)) + case complex128: + re = real(z) + im = imag(z) + default: + panic("unknown complex type") + } + return +} + +func ComplexAbs[T Complex](a T) T { + // TODO use direct conversion instead of realimag once #50937 is fixed + r, i := realimag(a) + // r := float64(real(a)) + // i := float64(imag(a)) + d := math.Sqrt(r*r + i*i) + return T(complex(d, 0)) +} + +// OrderedAbsDifference returns the absolute value of the difference +// between a and b, where a and b are of an ordered type. +func OrderedAbsDifference[T OrderedNumeric](a, b T) T { + return absDifference(a, b, Abs[T]) +} + +// ComplexAbsDifference returns the absolute value of the difference +// between a and b, where a and b are of a complex type. +func ComplexAbsDifference[T Complex](a, b T) T { + return absDifference(a, b, ComplexAbs[T]) +} + +func main() { + if got, want := OrderedAbsDifference(1.0, -2.0), 3.0; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := OrderedAbsDifference(-1.0, 2.0), 3.0; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := OrderedAbsDifference(-20, 15), 35; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + + if got, want := ComplexAbsDifference(5.0+2.0i, 2.0-2.0i), 5+0i; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } + if got, want := ComplexAbsDifference(2.0-2.0i, 5.0+2.0i), 5+0i; got != want { + panic(fmt.Sprintf("got = %v, want = %v", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/absdiffimp.go b/platform/dbops/binaries/go/go/test/typeparam/absdiffimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/absdiffimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/absdiffimp2.go b/platform/dbops/binaries/go/go/test/typeparam/absdiffimp2.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/absdiffimp2.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/adder.go b/platform/dbops/binaries/go/go/test/typeparam/adder.go new file mode 100644 index 0000000000000000000000000000000000000000..fbb492514c3c1d46392a1d94fc93ddf9c5e11a2d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/adder.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type AddType interface { + int | int64 | string +} + +// Add can add numbers or strings +func Add[T AddType](a, b T) T { + return a + b +} + +func main() { + if got, want := Add(5, 3), 8; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := Add("ab", "cd"), "abcd"; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/aliasimp.go b/platform/dbops/binaries/go/go/test/typeparam/aliasimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/aliasimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/append.go b/platform/dbops/binaries/go/go/test/typeparam/append.go new file mode 100644 index 0000000000000000000000000000000000000000..61682625c1d4dbb4e1b065ef87f6aa226e5d9699 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/append.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Recv <-chan int + +type sliceOf[E any] interface { + ~[]E +} + +func _Append[S sliceOf[T], T any](s S, t ...T) S { + return append(s, t...) +} + +func main() { + recv := make(Recv) + a := _Append([]Recv{recv}, recv) + if len(a) != 2 || a[0] != recv || a[1] != recv { + panic(a) + } + + recv2 := make(chan<- int) + a2 := _Append([]chan<- int{recv2}, recv2) + if len(a2) != 2 || a2[0] != recv2 || a2[1] != recv2 { + panic(a) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/boundmethod.go b/platform/dbops/binaries/go/go/test/typeparam/boundmethod.go new file mode 100644 index 0000000000000000000000000000000000000000..b78318cced6f08df087c4e9bc05b98c3b43bbb90 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/boundmethod.go @@ -0,0 +1,108 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This test illustrates how a type bound method (String below) can be implemented +// either by a concrete type (myint below) or an instantiated generic type +// (StringInt[myint] below). + +package main + +import ( + "fmt" + "reflect" + "strconv" +) + +type myint int + +//go:noinline +func (m myint) String() string { + return strconv.Itoa(int(m)) +} + +type Stringer interface { + String() string +} + +func stringify[T Stringer](s []T) (ret []string) { + for _, v := range s { + // Test normal bounds method call on type param + x1 := v.String() + + // Test converting type param to its bound interface first + v1 := Stringer(v) + x2 := v1.String() + + // Test method expression with type param type + f1 := T.String + x3 := f1(v) + + // Test creating and calling closure equivalent to the method expression + f2 := func(v1 T) string { + return Stringer(v1).String() + } + x4 := f2(v) + + if x1 != x2 || x2 != x3 || x3 != x4 { + panic(fmt.Sprintf("Mismatched values %v, %v, %v, %v\n", x1, x2, x3, x4)) + } + + ret = append(ret, v.String()) + } + return ret +} + +type Ints interface { + ~int32 | ~int +} + +// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). +// type StringInt[T Ints] T +// +// //go:noinline +// func (m StringInt[T]) String() string { +// return strconv.Itoa(int(m)) +// } + +type StringStruct[T Ints] struct { + f T +} + +func (m StringStruct[T]) String() string { + return strconv.Itoa(int(m.f)) +} + +func main() { + x := []myint{myint(1), myint(2), myint(3)} + + // stringify on a normal type, whose bound method is associated with the base type. + got := stringify(x) + want := []string{"1", "2", "3"} + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). + // x2 := []StringInt[myint]{StringInt[myint](5), StringInt[myint](7), StringInt[myint](6)} + // + // // stringify on an instantiated type, whose bound method is associated with + // // the generic type StringInt[T], which maps directly to T. + // got2 := stringify(x2) + // want2 := []string{"5", "7", "6"} + // if !reflect.DeepEqual(got2, want2) { + // panic(fmt.Sprintf("got %s, want %s", got2, want2)) + // } + + // stringify on an instantiated type, whose bound method is associated with + // the generic type StringStruct[T], which maps to a struct containing T. + x3 := []StringStruct[myint]{StringStruct[myint]{f: 11}, StringStruct[myint]{f: 10}, StringStruct[myint]{f: 9}} + + got3 := stringify(x3) + want3 := []string{"11", "10", "9"} + if !reflect.DeepEqual(got3, want3) { + panic(fmt.Sprintf("got %s, want %s", got3, want3)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/builtins.go b/platform/dbops/binaries/go/go/test/typeparam/builtins.go new file mode 100644 index 0000000000000000000000000000000000000000..763d7202d01a393023aa927ec914c9174230bc4d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/builtins.go @@ -0,0 +1,112 @@ +// compile + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file tests built-in calls on generic types. + +// derived and expanded from cmd/compile/internal/types2/testdata/check/builtins.go2 + +package builtins + +// close + +type C0 interface{ int } +type C1 interface{ chan int } +type C2 interface{ chan int | <-chan int } +type C3 interface{ chan int | chan float32 } +type C4 interface{ chan int | chan<- int } +type C5[T any] interface{ ~chan T | chan<- T } + +func f1[T C1](ch T) { + close(ch) +} + +func f2[T C3](ch T) { + close(ch) +} + +func f3[T C4](ch T) { + close(ch) +} + +func f4[T C5[X], X any](ch T) { + close(ch) +} + +// delete + +type M0 interface{ int } +type M1 interface{ map[string]int } +type M2 interface { + map[string]int | map[string]float64 +} +type M3 interface{ map[string]int | map[rune]int } +type M4[K comparable, V any] interface{ map[K]V | map[rune]V } + +func g1[T M1](m T) { + delete(m, "foo") +} + +func g2[T M2](m T) { + delete(m, "foo") +} + +func g3[T M4[rune, V], V any](m T) { + delete(m, 'k') +} + +// make + +func m1[ + S1 interface{ []int }, + S2 interface{ []int | chan int }, + + M1 interface{ map[string]int }, + M2 interface{ map[string]int | chan int }, + + C1 interface{ chan int }, + C2 interface{ chan int | chan string }, +]() { + _ = make([]int, 10) + _ = make(m1S0, 10) + _ = make(S1, 10) + _ = make(S1, 10, 20) + + _ = make(map[string]int) + _ = make(m1M0) + _ = make(M1) + _ = make(M1, 10) + + _ = make(chan int) + _ = make(m1C0) + _ = make(C1) + _ = make(C1, 10) +} +// TODO: put these type declarations back inside m1 when issue 47631 is fixed. +type m1S0 []int +type m1M0 map[string]int +type m1C0 chan int + +// len/cap + +type Slice[T any] interface { + []T +} + +func c1[T any, S Slice[T]]() { + x := make(S, 5, 10) + _ = len(x) + _ = cap(x) +} + +// append + +func a1[T any, S Slice[T]]() { + x := make(S, 5) + y := make(S, 2) + var z T + _ = append(x, y...) + _ = append(x, z) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/chans.go b/platform/dbops/binaries/go/go/test/typeparam/chans.go new file mode 100644 index 0000000000000000000000000000000000000000..d73ce6e5316735b11875b6c7ac1cd33c6564ffa0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/chans.go @@ -0,0 +1,413 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package chans provides utility functions for working with channels. +package main + +import ( + "context" + "fmt" + "runtime" + "sort" + "sync" + "time" +) + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// _ReadAll reads from c until the channel is closed or the context is +// canceled, returning all the values read. +func _ReadAll[Elem any](ctx context.Context, c <-chan Elem) []Elem { + var r []Elem + for { + select { + case <-ctx.Done(): + return r + case v, ok := <-c: + if !ok { + return r + } + r = append(r, v) + } + } +} + +// _Merge merges two channels into a single channel. +// This will leave a goroutine running until either both channels are closed +// or the context is canceled, at which point the returned channel is closed. +func _Merge[Elem any](ctx context.Context, c1, c2 <-chan Elem) <-chan Elem { + r := make(chan Elem) + go func(ctx context.Context, c1, c2 <-chan Elem, r chan<- Elem) { + defer close(r) + for c1 != nil || c2 != nil { + select { + case <-ctx.Done(): + return + case v1, ok := <-c1: + if ok { + r <- v1 + } else { + c1 = nil + } + case v2, ok := <-c2: + if ok { + r <- v2 + } else { + c2 = nil + } + } + } + }(ctx, c1, c2, r) + return r +} + +// _Filter calls f on each value read from c. If f returns true the value +// is sent on the returned channel. This will leave a goroutine running +// until c is closed or the context is canceled, at which point the +// returned channel is closed. +func _Filter[Elem any](ctx context.Context, c <-chan Elem, f func(Elem) bool) <-chan Elem { + r := make(chan Elem) + go func(ctx context.Context, c <-chan Elem, f func(Elem) bool, r chan<- Elem) { + defer close(r) + for { + select { + case <-ctx.Done(): + return + case v, ok := <-c: + if !ok { + return + } + if f(v) { + r <- v + } + } + } + }(ctx, c, f, r) + return r +} + +// _Sink returns a channel that discards all values sent to it. +// This will leave a goroutine running until the context is canceled +// or the returned channel is closed. +func _Sink[Elem any](ctx context.Context) chan<- Elem { + r := make(chan Elem) + go func(ctx context.Context, r <-chan Elem) { + for { + select { + case <-ctx.Done(): + return + case _, ok := <-r: + if !ok { + return + } + } + } + }(ctx, r) + return r +} + +// An Exclusive is a value that may only be used by a single goroutine +// at a time. This is implemented using channels rather than a mutex. +type _Exclusive[Val any] struct { + c chan Val +} + +// _MakeExclusive makes an initialized exclusive value. +func _MakeExclusive[Val any](initial Val) *_Exclusive[Val] { + r := &_Exclusive[Val]{ + c: make(chan Val, 1), + } + r.c <- initial + return r +} + +// _Acquire acquires the exclusive value for private use. +// It must be released using the Release method. +func (e *_Exclusive[Val]) Acquire() Val { + return <-e.c +} + +// TryAcquire attempts to acquire the value. The ok result reports whether +// the value was acquired. If the value is acquired, it must be released +// using the Release method. +func (e *_Exclusive[Val]) TryAcquire() (v Val, ok bool) { + select { + case r := <-e.c: + return r, true + default: + return v, false + } +} + +// Release updates and releases the value. +// This method panics if the value has not been acquired. +func (e *_Exclusive[Val]) Release(v Val) { + select { + case e.c <- v: + default: + panic("_Exclusive Release without Acquire") + } +} + +// Ranger returns a Sender and a Receiver. The Receiver provides a +// Next method to retrieve values. The Sender provides a Send method +// to send values and a Close method to stop sending values. The Next +// method indicates when the Sender has been closed, and the Send +// method indicates when the Receiver has been freed. +// +// This is a convenient way to exit a goroutine sending values when +// the receiver stops reading them. +func _Ranger[Elem any]() (*_Sender[Elem], *_Receiver[Elem]) { + c := make(chan Elem) + d := make(chan struct{}) + s := &_Sender[Elem]{ + values: c, + done: d, + } + r := &_Receiver[Elem]{ + values: c, + done: d, + } + runtime.SetFinalizer(r, (*_Receiver[Elem]).finalize) + return s, r +} + +// A _Sender is used to send values to a Receiver. +type _Sender[Elem any] struct { + values chan<- Elem + done <-chan struct{} +} + +// Send sends a value to the receiver. It reports whether the value was sent. +// The value will not be sent if the context is closed or the receiver +// is freed. +func (s *_Sender[Elem]) Send(ctx context.Context, v Elem) bool { + select { + case <-ctx.Done(): + return false + case s.values <- v: + return true + case <-s.done: + return false + } +} + +// Close tells the receiver that no more values will arrive. +// After Close is called, the _Sender may no longer be used. +func (s *_Sender[Elem]) Close() { + close(s.values) +} + +// A _Receiver receives values from a _Sender. +type _Receiver[Elem any] struct { + values <-chan Elem + done chan<- struct{} +} + +// Next returns the next value from the channel. The bool result indicates +// whether the value is valid. +func (r *_Receiver[Elem]) Next(ctx context.Context) (v Elem, ok bool) { + select { + case <-ctx.Done(): + case v, ok = <-r.values: + } + return v, ok +} + +// finalize is a finalizer for the receiver. +func (r *_Receiver[Elem]) finalize() { + close(r.done) +} + +func TestReadAll() { + c := make(chan int) + go func() { + c <- 4 + c <- 2 + c <- 5 + close(c) + }() + got := _ReadAll(context.Background(), c) + want := []int{4, 2, 5} + if !_SliceEqual(got, want) { + panic(fmt.Sprintf("_ReadAll returned %v, want %v", got, want)) + } +} + +func TestMerge() { + c1 := make(chan int) + c2 := make(chan int) + go func() { + c1 <- 1 + c1 <- 3 + c1 <- 5 + close(c1) + }() + go func() { + c2 <- 2 + c2 <- 4 + c2 <- 6 + close(c2) + }() + ctx := context.Background() + got := _ReadAll(ctx, _Merge(ctx, c1, c2)) + sort.Ints(got) + want := []int{1, 2, 3, 4, 5, 6} + if !_SliceEqual(got, want) { + panic(fmt.Sprintf("_Merge returned %v, want %v", got, want)) + } +} + +func TestFilter() { + c := make(chan int) + go func() { + c <- 1 + c <- 2 + c <- 3 + close(c) + }() + even := func(i int) bool { return i%2 == 0 } + ctx := context.Background() + got := _ReadAll(ctx, _Filter(ctx, c, even)) + want := []int{2} + if !_SliceEqual(got, want) { + panic(fmt.Sprintf("_Filter returned %v, want %v", got, want)) + } +} + +func TestSink() { + c := _Sink[int](context.Background()) + after := time.NewTimer(time.Minute) + defer after.Stop() + send := func(v int) { + select { + case c <- v: + case <-after.C: + panic("timed out sending to _Sink") + } + } + send(1) + send(2) + send(3) + close(c) +} + +func TestExclusive() { + val := 0 + ex := _MakeExclusive(&val) + + var wg sync.WaitGroup + f := func() { + defer wg.Done() + for i := 0; i < 10; i++ { + p := ex.Acquire() + (*p)++ + ex.Release(p) + } + } + + wg.Add(2) + go f() + go f() + + wg.Wait() + if val != 20 { + panic(fmt.Sprintf("after Acquire/Release loop got %d, want 20", val)) + } +} + +func TestExclusiveTry() { + s := "" + ex := _MakeExclusive(&s) + p, ok := ex.TryAcquire() + if !ok { + panic("TryAcquire failed") + } + *p = "a" + + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + _, ok := ex.TryAcquire() + if ok { + panic(fmt.Sprintf("TryAcquire succeeded unexpectedly")) + } + }() + wg.Wait() + + ex.Release(p) + + p, ok = ex.TryAcquire() + if !ok { + panic(fmt.Sprintf("TryAcquire failed")) + } +} + +func TestRanger() { + s, r := _Ranger[int]() + + ctx := context.Background() + go func() { + // Receive one value then exit. + v, ok := r.Next(ctx) + if !ok { + panic(fmt.Sprintf("did not receive any values")) + } else if v != 1 { + panic(fmt.Sprintf("received %d, want 1", v)) + } + }() + + c1 := make(chan bool) + c2 := make(chan bool) + go func() { + defer close(c2) + if !s.Send(ctx, 1) { + panic(fmt.Sprintf("Send failed unexpectedly")) + } + close(c1) + if s.Send(ctx, 2) { + panic(fmt.Sprintf("Send succeeded unexpectedly")) + } + }() + + <-c1 + + // Force a garbage collection to try to get the finalizers to run. + runtime.GC() + + select { + case <-c2: + case <-time.After(time.Minute): + panic("_Ranger Send should have failed, but timed out") + } +} + +func main() { + TestReadAll() + TestMerge() + TestFilter() + TestSink() + TestExclusive() + TestExclusiveTry() + TestRanger() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/chansimp.go b/platform/dbops/binaries/go/go/test/typeparam/chansimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/chansimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/combine.go b/platform/dbops/binaries/go/go/test/typeparam/combine.go new file mode 100644 index 0000000000000000000000000000000000000000..361708f1ebb1df0ea3a1678de8b3f7b32be24aca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/combine.go @@ -0,0 +1,65 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Gen[A any] func() (A, bool) + +func Combine[T1, T2, T any](g1 Gen[T1], g2 Gen[T2], join func(T1, T2) T) Gen[T] { + return func() (T, bool) { + var t T + t1, ok := g1() + if !ok { + return t, false + } + t2, ok := g2() + if !ok { + return t, false + } + return join(t1, t2), true + } +} + +type Pair[A, B any] struct { + A A + B B +} + +func _NewPair[A, B any](a A, b B) Pair[A, B] { + return Pair[A, B]{a, b} +} + +func Combine2[A, B any](ga Gen[A], gb Gen[B]) Gen[Pair[A, B]] { + return Combine(ga, gb, _NewPair[A, B]) +} + +func main() { + var g1 Gen[int] = func() (int, bool) { return 3, true } + var g2 Gen[string] = func() (string, bool) { return "x", false } + var g3 Gen[string] = func() (string, bool) { return "y", true } + + gc := Combine(g1, g2, _NewPair[int, string]) + if got, ok := gc(); ok { + panic(fmt.Sprintf("got %v, %v, wanted -/false", got, ok)) + } + gc2 := Combine2(g1, g2) + if got, ok := gc2(); ok { + panic(fmt.Sprintf("got %v, %v, wanted -/false", got, ok)) + } + + gc3 := Combine(g1, g3, _NewPair[int, string]) + if got, ok := gc3(); !ok || got.A != 3 || got.B != "y" { + panic(fmt.Sprintf("got %v, %v, wanted {3, y}, true", got, ok)) + } + gc4 := Combine2(g1, g3) + if got, ok := gc4(); !ok || got.A != 3 || got.B != "y" { + panic(fmt.Sprintf("got %v, %v, wanted {3, y}, true", got, ok)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/cons.go b/platform/dbops/binaries/go/go/test/typeparam/cons.go new file mode 100644 index 0000000000000000000000000000000000000000..733e5793b16dbc30f939d53df365117fcfd95ab7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/cons.go @@ -0,0 +1,100 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +// Overriding the predeclare "any", so it can be used as a type constraint or a type +// argument +type any interface{} + +type Function[a, b any] interface { + Apply(x a) b +} + +type incr struct{ n int } + +func (this incr) Apply(x int) int { + return x + this.n +} + +type pos struct{} + +func (this pos) Apply(x int) bool { + return x > 0 +} + +type compose[a, b, c any] struct { + f Function[a, b] + g Function[b, c] +} + +func (this compose[a, b, c]) Apply(x a) c { + return this.g.Apply(this.f.Apply(x)) +} + +type _Eq[a any] interface { + Equal(a) bool +} + +type Int int + +func (this Int) Equal(that int) bool { + return int(this) == that +} + +type List[a any] interface { + Match(casenil Function[Nil[a], any], casecons Function[Cons[a], any]) any +} + +type Nil[a any] struct { +} + +func (xs Nil[a]) Match(casenil Function[Nil[a], any], casecons Function[Cons[a], any]) any { + return casenil.Apply(xs) +} + +type Cons[a any] struct { + Head a + Tail List[a] +} + +func (xs Cons[a]) Match(casenil Function[Nil[a], any], casecons Function[Cons[a], any]) any { + return casecons.Apply(xs) +} + +type mapNil[a, b any] struct { +} + +func (m mapNil[a, b]) Apply(_ Nil[a]) any { + return Nil[b]{} +} + +type mapCons[a, b any] struct { + f Function[a, b] +} + +func (m mapCons[a, b]) Apply(xs Cons[a]) any { + return Cons[b]{m.f.Apply(xs.Head), Map[a, b](m.f, xs.Tail)} +} + +func Map[a, b any](f Function[a, b], xs List[a]) List[b] { + return xs.Match(mapNil[a, b]{}, mapCons[a, b]{f}).(List[b]) +} + +func main() { + var xs List[int] = Cons[int]{3, Cons[int]{6, Nil[int]{}}} + var ys List[int] = Map[int, int](incr{-5}, xs) + var xz List[bool] = Map[int, bool](pos{}, ys) + cs1 := xz.(Cons[bool]) + cs2 := cs1.Tail.(Cons[bool]) + _, ok := cs2.Tail.(Nil[bool]) + if cs1.Head != false || cs2.Head != true || !ok { + panic(fmt.Sprintf("got %v, %v, %v, expected false, true, true", + cs1.Head, cs2.Head, ok)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/dedup.go b/platform/dbops/binaries/go/go/test/typeparam/dedup.go new file mode 100644 index 0000000000000000000000000000000000000000..3b98e03d9d439aa03859fdf3d33b41c18893806d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dedup.go @@ -0,0 +1,12 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Note: this doesn't really test the deduplication of +// instantiations. It just provides an easy mechanism to build a +// binary that you can then check with objdump manually to make sure +// deduplication is happening. TODO: automate this somehow? + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/dedup.out b/platform/dbops/binaries/go/go/test/typeparam/dedup.out new file mode 100644 index 0000000000000000000000000000000000000000..1140ff52e2ba1f46b1315269500c551a9bd48768 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dedup.out @@ -0,0 +1,4 @@ +true +true +true +true diff --git a/platform/dbops/binaries/go/go/test/typeparam/devirtualize1.go b/platform/dbops/binaries/go/go/test/typeparam/devirtualize1.go new file mode 100644 index 0000000000000000000000000000000000000000..fb26225e6e8c46af3ced9f78d528b1a1b0cee033 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/devirtualize1.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type S struct { + x int +} + +func (t *S) M1() { +} + +func F[T any](x T) any { + return x +} + +func main() { + F(&S{}).(interface{ M1() }).M1() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/devirtualize2.go b/platform/dbops/binaries/go/go/test/typeparam/devirtualize2.go new file mode 100644 index 0000000000000000000000000000000000000000..ca6dc8fa86bdc5e020c490ea6bea1a602fbf5c2c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/devirtualize2.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type S struct { + x int +} + +func (t *S) M1() { +} +func (t *S) M2() { +} + +type I interface { + M1() +} + +func F[T I](x T) I { + return x +} + +func main() { + F(&S{}).(interface{ M2() }).M2() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture-noinline.go b/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture-noinline.go new file mode 100644 index 0000000000000000000000000000000000000000..4c5e7ec7a6e008b8c0aecadbc4488549a717692e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture-noinline.go @@ -0,0 +1,126 @@ +// run -gcflags="-l" + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test situations where functions/methods are not +// immediately called and we need to capture the dictionary +// required for later invocation. + +package main + +func main() { + functions() + methodExpressions() + methodValues() + interfaceMethods() + globals() +} + +func g0[T any](x T) { +} +func g1[T any](x T) T { + return x +} +func g2[T any](x T) (T, T) { + return x, x +} + +func functions() { + f0 := g0[int] + f0(7) + f1 := g1[int] + is7(f1(7)) + f2 := g2[int] + is77(f2(7)) +} + +func is7(x int) { + if x != 7 { + println(x) + panic("assertion failed") + } +} +func is77(x, y int) { + if x != 7 || y != 7 { + println(x, y) + panic("assertion failed") + } +} + +type s[T any] struct { + a T +} + +func (x s[T]) g0() { +} +func (x s[T]) g1() T { + return x.a +} +func (x s[T]) g2() (T, T) { + return x.a, x.a +} + +func methodExpressions() { + x := s[int]{a: 7} + f0 := s[int].g0 + f0(x) + f1 := s[int].g1 + is7(f1(x)) + f2 := s[int].g2 + is77(f2(x)) +} + +func methodValues() { + x := s[int]{a: 7} + f0 := x.g0 + f0() + f1 := x.g1 + is7(f1()) + f2 := x.g2 + is77(f2()) +} + +var x interface { + g0() + g1() int + g2() (int, int) +} = s[int]{a: 7} +var y interface{} = s[int]{a: 7} + +func interfaceMethods() { + x.g0() + is7(x.g1()) + is77(x.g2()) + y.(interface{ g0() }).g0() + is7(y.(interface{ g1() int }).g1()) + is77(y.(interface{ g2() (int, int) }).g2()) +} + +// Also check for instantiations outside functions. +var gg0 = g0[int] +var gg1 = g1[int] +var gg2 = g2[int] + +var hh0 = s[int].g0 +var hh1 = s[int].g1 +var hh2 = s[int].g2 + +var xtop = s[int]{a: 7} +var ii0 = x.g0 +var ii1 = x.g1 +var ii2 = x.g2 + +func globals() { + gg0(7) + is7(gg1(7)) + is77(gg2(7)) + x := s[int]{a: 7} + hh0(x) + is7(hh1(x)) + is77(hh2(x)) + ii0() + is7(ii1()) + is77(ii2()) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture.go b/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture.go new file mode 100644 index 0000000000000000000000000000000000000000..b503abb18f3560375b18b03352efe536e725c470 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dictionaryCapture.go @@ -0,0 +1,203 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test situations where functions/methods are not +// immediately called and we need to capture the dictionary +// required for later invocation. + +package main + +import ( + "fmt" +) + +func main() { + functions() + methodExpressions() + genMethodExpressions[int](7) + methodValues() + genMethodValues[int](7) + interfaceMethods() + globals() + recursive() +} + +func g0[T any](x T) { +} +func g1[T any](x T) T { + return x +} +func g2[T any](x T) (T, T) { + return x, x +} + +func functions() { + f0 := g0[int] + f0(7) + f1 := g1[int] + is7(f1(7)) + f2 := g2[int] + is77(f2(7)) +} + +func is7(x int) { + if x != 7 { + println(x) + panic("assertion failed") + } +} +func is77(x, y int) { + if x != 7 || y != 7 { + println(x, y) + panic("assertion failed") + } +} + +type s[T any] struct { + a T +} + +func (x s[T]) g0() { +} +func (x s[T]) g1() T { + return x.a +} +func (x s[T]) g2() (T, T) { + return x.a, x.a +} + +func methodExpressions() { + x := s[int]{a: 7} + f0 := s[int].g0 + f0(x) + f0p := (*s[int]).g0 + f0p(&x) + f1 := s[int].g1 + is7(f1(x)) + f1p := (*s[int]).g1 + is7(f1p(&x)) + f2 := s[int].g2 + is77(f2(x)) + f2p := (*s[int]).g2 + is77(f2p(&x)) +} + +func genMethodExpressions[T comparable](want T) { + x := s[T]{a: want} + f0 := s[T].g0 + f0(x) + f0p := (*s[T]).g0 + f0p(&x) + f1 := s[T].g1 + if got := f1(x); got != want { + panic(fmt.Sprintf("f1(x) == %d, want %d", got, want)) + } + f1p := (*s[T]).g1 + if got := f1p(&x); got != want { + panic(fmt.Sprintf("f1p(&x) == %d, want %d", got, want)) + } + f2 := s[T].g2 + if got1, got2 := f2(x); got1 != want || got2 != want { + panic(fmt.Sprintf("f2(x) == %d, %d, want %d, %d", got1, got2, want, want)) + } +} + +func methodValues() { + x := s[int]{a: 7} + f0 := x.g0 + f0() + f1 := x.g1 + is7(f1()) + f2 := x.g2 + is77(f2()) +} + +func genMethodValues[T comparable](want T) { + x := s[T]{a: want} + f0 := x.g0 + f0() + f1 := x.g1 + if got := f1(); got != want { + panic(fmt.Sprintf("f1() == %d, want %d", got, want)) + } + f2 := x.g2 + if got1, got2 := f2(); got1 != want || got2 != want { + panic(fmt.Sprintf("f2() == %d, %d, want %d, %d", got1, got2, want, want)) + } +} + +var x interface { + g0() + g1() int + g2() (int, int) +} = s[int]{a: 7} +var y interface{} = s[int]{a: 7} + +func interfaceMethods() { + x.g0() + is7(x.g1()) + is77(x.g2()) + y.(interface{ g0() }).g0() + is7(y.(interface{ g1() int }).g1()) + is77(y.(interface{ g2() (int, int) }).g2()) +} + +// Also check for instantiations outside functions. +var gg0 = g0[int] +var gg1 = g1[int] +var gg2 = g2[int] + +var hh0 = s[int].g0 +var hh1 = s[int].g1 +var hh2 = s[int].g2 + +var xtop = s[int]{a: 7} +var ii0 = x.g0 +var ii1 = x.g1 +var ii2 = x.g2 + +func globals() { + gg0(7) + is7(gg1(7)) + is77(gg2(7)) + x := s[int]{a: 7} + hh0(x) + is7(hh1(x)) + is77(hh2(x)) + ii0() + is7(ii1()) + is77(ii2()) +} + +func recursive() { + if got, want := recur1[int](5), 110; got != want { + panic(fmt.Sprintf("recur1[int](5) = %d, want = %d", got, want)) + } +} + +type Integer interface { + int | int32 | int64 +} + +func recur1[T Integer](n T) T { + if n == 0 || n == 1 { + return T(1) + } else { + return n * recur2(n-1) + } +} + +func recur2[T Integer](n T) T { + list := make([]T, n) + for i, _ := range list { + list[i] = T(i + 1) + } + var sum T + for _, elt := range list { + sum += elt + } + return sum + recur1(n-1) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/dottype.go b/platform/dbops/binaries/go/go/test/typeparam/dottype.go new file mode 100644 index 0000000000000000000000000000000000000000..9f1630d19cd36766873ef942fa166fd96200bd5d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dottype.go @@ -0,0 +1,86 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T any](x interface{}) T { + return x.(T) +} +func f2[T any](x interface{}) (T, bool) { + t, ok := x.(T) + return t, ok +} + +type I interface { + foo() +} + +type myint int + +func (myint) foo() { +} + +type myfloat float64 + +func (myfloat) foo() { +} + +func g[T I](x I) T { + return x.(T) +} +func g2[T I](x I) (T, bool) { + t, ok := x.(T) + return t, ok +} + +func h[T any](x interface{}) struct{ a, b T } { + return x.(struct{ a, b T }) +} + +func k[T any](x interface{}) interface{ bar() T } { + return x.(interface{ bar() T }) +} + +type mybar int + +func (x mybar) bar() int { + return int(x) +} + +func main() { + var i interface{} = int(3) + var j I = myint(3) + var x interface{} = float64(3) + var y I = myfloat(3) + + println(f[int](i)) + shouldpanic(func() { f[int](x) }) + println(f2[int](i)) + println(f2[int](x)) + + println(g[myint](j)) + shouldpanic(func() { g[myint](y) }) + println(g2[myint](j)) + println(g2[myint](y)) + + println(h[int](struct{ a, b int }{3, 5}).a) + + println(k[int](mybar(3)).bar()) + + type large struct {a,b,c,d,e,f int} + println(f[large](large{}).a) + l2, ok := f2[large](large{}) + println(l2.a, ok) +} +func shouldpanic(x func()) { + defer func() { + e := recover() + if e == nil { + panic("didn't panic") + } + }() + x() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/dottype.out b/platform/dbops/binaries/go/go/test/typeparam/dottype.out new file mode 100644 index 0000000000000000000000000000000000000000..8e6a3c25526093a1175bc60dad33b267fa5ad0ee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/dottype.out @@ -0,0 +1,10 @@ +3 +3 true +0 false +3 +3 true +0 false +3 +3 +0 +0 true diff --git a/platform/dbops/binaries/go/go/test/typeparam/double.go b/platform/dbops/binaries/go/go/test/typeparam/double.go new file mode 100644 index 0000000000000000000000000000000000000000..fbbe602d1336a1e42a6a33e140996f393e934fd2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/double.go @@ -0,0 +1,72 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "reflect" +) + +type Number interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 +} + +type MySlice []int +type MyFloatSlice []float64 + +type _SliceOf[E any] interface { + ~[]E +} + +func _DoubleElems[S _SliceOf[E], E Number](s S) S { + r := make(S, len(s)) + for i, v := range s { + r[i] = v + v + } + return r +} + +// Test use of untyped constant in an expression with a generically-typed parameter +func _DoubleElems2[S _SliceOf[E], E Number](s S) S { + r := make(S, len(s)) + for i, v := range s { + r[i] = v * 2 + } + return r +} + +func main() { + arg := MySlice{1, 2, 3} + want := MySlice{2, 4, 6} + got := _DoubleElems[MySlice, int](arg) + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + // constraint type inference + got = _DoubleElems[MySlice](arg) + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + got = _DoubleElems(arg) + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + farg := MyFloatSlice{1.2, 2.0, 3.5} + fwant := MyFloatSlice{2.4, 4.0, 7.0} + fgot := _DoubleElems(farg) + if !reflect.DeepEqual(fgot, fwant) { + panic(fmt.Sprintf("got %s, want %s", fgot, fwant)) + } + + fgot = _DoubleElems2(farg) + if !reflect.DeepEqual(fgot, fwant) { + panic(fmt.Sprintf("got %s, want %s", fgot, fwant)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/eface.go b/platform/dbops/binaries/go/go/test/typeparam/eface.go new file mode 100644 index 0000000000000000000000000000000000000000..05d5503c82f1a2f7d631667a13347be0de3ddb48 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/eface.go @@ -0,0 +1,67 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Make sure we handle instantiated empty interfaces. + +package main + +type E[T any] interface { +} + +//go:noinline +func f[T any](x E[T]) interface{} { + return x +} + +//go:noinline +func g[T any](x interface{}) E[T] { + return x +} + +type I[T any] interface { + foo() +} + +type myint int + +func (x myint) foo() {} + +//go:noinline +func h[T any](x I[T]) interface{ foo() } { + return x +} + +//go:noinline +func i[T any](x interface{ foo() }) I[T] { + return x +} + +func main() { + if f[int](1) != 1 { + println("test 1 failed") + } + if f[int](2) != (interface{})(2) { + println("test 2 failed") + } + if g[int](3) != 3 { + println("test 3 failed") + } + if g[int](4) != (E[int])(4) { + println("test 4 failed") + } + if h[int](myint(5)) != myint(5) { + println("test 5 failed") + } + if h[int](myint(6)) != interface{ foo() }(myint(6)) { + println("test 6 failed") + } + if i[int](myint(7)) != myint(7) { + println("test 7 failed") + } + if i[int](myint(8)) != I[int](myint(8)) { + println("test 8 failed") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/equal.go b/platform/dbops/binaries/go/go/test/typeparam/equal.go new file mode 100644 index 0000000000000000000000000000000000000000..21e210345bb0e1429c98c4a6f1069759cfcb4f31 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/equal.go @@ -0,0 +1,69 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// comparisons of type parameters to interfaces + +package main + +func f[T comparable](t, u T) bool { + // Comparing two type parameters directly. + // (Not really testing comparisons to interfaces, but just 'cause we're here.) + return t == u +} + +func g[T comparable](t T, i interface{}) bool { + // Compare type parameter value to empty interface. + return t == i +} + +type I interface { + foo() +} + +type C interface { + comparable + I +} + +func h[T C](t T, i I) bool { + // Compare type parameter value to nonempty interface. + return t == i +} + +type myint int + +func (x myint) foo() { +} + +func k[T comparable](t T, i interface{}) bool { + // Compare derived type value to interface. + return struct{ a, b T }{t, t} == i +} + +func main() { + assert(f(3, 3)) + assert(!f(3, 5)) + assert(g(3, 3)) + assert(!g(3, 5)) + assert(h(myint(3), myint(3))) + assert(!h(myint(3), myint(5))) + + type S struct{ a, b float64 } + + assert(f(S{3, 5}, S{3, 5})) + assert(!f(S{3, 5}, S{4, 6})) + assert(g(S{3, 5}, S{3, 5})) + assert(!g(S{3, 5}, S{4, 6})) + + assert(k(3, struct{ a, b int }{3, 3})) + assert(!k(3, struct{ a, b int }{3, 4})) +} + +func assert(b bool) { + if !b { + panic("assertion failed") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/fact.go b/platform/dbops/binaries/go/go/test/typeparam/fact.go new file mode 100644 index 0000000000000000000000000000000000000000..3c9a13aa736f111ac955632d9379e329d5fab040 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/fact.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func fact[T interface{ ~int | ~int64 | ~float64 }](n T) T { + if n == 1 { + return 1 + } + return n * fact(n-1) +} + +func main() { + const want = 120 + + if got := fact(5); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := fact[int64](5); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := fact(5.0); got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/factimp.go b/platform/dbops/binaries/go/go/test/typeparam/factimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/factimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/gencrawler.go b/platform/dbops/binaries/go/go/test/typeparam/gencrawler.go new file mode 100644 index 0000000000000000000000000000000000000000..66b5f433544a4d3c6dc8dbbfa654771decff8375 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/gencrawler.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Testing that all methods of a private generic type are exported, if a variable +// with that type is exported. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/gencrawler.out b/platform/dbops/binaries/go/go/test/typeparam/gencrawler.out new file mode 100644 index 0000000000000000000000000000000000000000..aa47d0d46d47a06090f436b0b851b76bb6f3b6e2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/gencrawler.out @@ -0,0 +1,2 @@ +0 +0 diff --git a/platform/dbops/binaries/go/go/test/typeparam/genembed.go b/platform/dbops/binaries/go/go/test/typeparam/genembed.go new file mode 100644 index 0000000000000000000000000000000000000000..6a11be1cb6912ae402c6a4211b5e893a6dd104bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/genembed.go @@ -0,0 +1,52 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test wrappers/interfaces for generic type embedding another generic type. + +package main + +import "fmt" + +type A[T any] struct { + B[T] +} + +type B[T any] struct { + val T +} + +func (b *B[T]) get() T { + return b.val +} + +type getter[T any] interface { + get() T +} + +//go:noinline +func doGet[T any](i getter[T]) T { + return i.get() +} + +//go:noline +func doGet2[T any](i interface{}) T { + i2 := i.(getter[T]) + return i2.get() +} + +func main() { + a := A[int]{B: B[int]{3}} + var i getter[int] = &a + + if got, want := doGet(i), 3; got != want { + panic(fmt.Sprintf("got %v, want %v", got, want)) + } + + as := A[string]{B: B[string]{"abc"}} + if got, want := doGet2[string](&as), "abc"; got != want { + panic(fmt.Sprintf("got %v, want %v", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/genembed2.go b/platform/dbops/binaries/go/go/test/typeparam/genembed2.go new file mode 100644 index 0000000000000000000000000000000000000000..f75731fd519e51e1b241aeb3f82cb006c87108bc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/genembed2.go @@ -0,0 +1,46 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test for declaration and use of a parameterized embedded field. + +package main + +import ( + "fmt" + "sync" +) + +type MyStruct[T any] struct { + val T +} + +type Lockable[T any] struct { + MyStruct[T] + mu sync.Mutex +} + +// Get returns the value stored in a Lockable. +func (l *Lockable[T]) Get() T { + l.mu.Lock() + defer l.mu.Unlock() + return l.MyStruct.val +} + +// Set sets the value in a Lockable. +func (l *Lockable[T]) Set(v T) { + l.mu.Lock() + defer l.mu.Unlock() + l.MyStruct = MyStruct[T]{v} +} + +func main() { + var li Lockable[int] + + li.Set(5) + if got, want := li.Get(), 5; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/geninline.go b/platform/dbops/binaries/go/go/test/typeparam/geninline.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/geninline.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/graph.go b/platform/dbops/binaries/go/go/test/typeparam/graph.go new file mode 100644 index 0000000000000000000000000000000000000000..5cd1faa76f523d7708df04c34f32093308281d4b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/graph.go @@ -0,0 +1,230 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "errors" + "fmt" +) + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// A Graph is a collection of nodes. A node may have an arbitrary number +// of edges. An edge connects two nodes. Both nodes and edges must be +// comparable. This is an undirected simple graph. +type _Graph[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]] struct { + nodes []_Node +} + +// _NodeC is the constraints on a node in a graph, given the _Edge type. +type _NodeC[_Edge any] interface { + comparable + Edges() []_Edge +} + +// Edgec is the constraints on an edge in a graph, given the _Node type. +type _EdgeC[_Node any] interface { + comparable + Nodes() (a, b _Node) +} + +// _New creates a new _Graph from a collection of Nodes. +func _New[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]](nodes []_Node) *_Graph[_Node, _Edge] { + return &_Graph[_Node, _Edge]{nodes: nodes} +} + +// nodePath holds the path to a node during ShortestPath. +// This should ideally be a type defined inside ShortestPath, +// but the translator tool doesn't support that. +type nodePath[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]] struct { + node _Node + path []_Edge +} + +// ShortestPath returns the shortest path between two nodes, +// as an ordered list of edges. If there are multiple shortest paths, +// which one is returned is unpredictable. +func (g *_Graph[_Node, _Edge]) ShortestPath(from, to _Node) ([]_Edge, error) { + visited := make(map[_Node]bool) + visited[from] = true + workqueue := []nodePath[_Node, _Edge]{nodePath[_Node, _Edge]{from, nil}} + for len(workqueue) > 0 { + current := workqueue + workqueue = nil + for _, np := range current { + edges := np.node.Edges() + for _, edge := range edges { + a, b := edge.Nodes() + if a == np.node { + a = b + } + if !visited[a] { + ve := append([]_Edge(nil), np.path...) + ve = append(ve, edge) + if a == to { + return ve, nil + } + workqueue = append(workqueue, nodePath[_Node, _Edge]{a, ve}) + visited[a] = true + } + } + } + } + return nil, errors.New("no path") +} + +type direction int + +const ( + north direction = iota + ne + east + se + south + sw + west + nw + up + down +) + +func (dir direction) String() string { + strs := map[direction]string{ + north: "north", + ne: "ne", + east: "east", + se: "se", + south: "south", + sw: "sw", + west: "west", + nw: "nw", + up: "up", + down: "down", + } + if str, ok := strs[dir]; ok { + return str + } + return fmt.Sprintf("direction %d", dir) +} + +type mazeRoom struct { + index int + exits [10]int +} + +type mazeEdge struct { + from, to int + dir direction +} + +// Edges returns the exits from the room. +func (m mazeRoom) Edges() []mazeEdge { + var r []mazeEdge + for i, exit := range m.exits { + if exit != 0 { + r = append(r, mazeEdge{ + from: m.index, + to: exit, + dir: direction(i), + }) + } + } + return r +} + +// Nodes returns the rooms connected by an edge. +//go:noinline +func (e mazeEdge) Nodes() (mazeRoom, mazeRoom) { + m1, ok := zork[e.from] + if !ok { + panic("bad edge") + } + m2, ok := zork[e.to] + if !ok { + panic("bad edge") + } + return m1, m2 +} + +// The first maze in Zork. Room indexes based on original Fortran data file. +// You are in a maze of twisty little passages, all alike. +var zork = map[int]mazeRoom{ + 11: {exits: [10]int{north: 11, south: 12, east: 14}}, // west to Troll Room + 12: {exits: [10]int{south: 11, north: 14, east: 13}}, + 13: {exits: [10]int{west: 12, north: 14, up: 16}}, + 14: {exits: [10]int{west: 13, north: 11, east: 15}}, + 15: {exits: [10]int{south: 14}}, // Dead End + 16: {exits: [10]int{east: 17, north: 13, sw: 18}}, // skeleton, etc. + 17: {exits: [10]int{west: 16}}, // Dead End + 18: {exits: [10]int{down: 16, east: 19, west: 18, up: 22}}, + 19: {exits: [10]int{up: 29, west: 18, ne: 15, east: 20, south: 30}}, + 20: {exits: [10]int{ne: 19, west: 20, se: 21}}, + 21: {exits: [10]int{north: 20}}, // Dead End + 22: {exits: [10]int{north: 18, east: 24, down: 23, south: 28, west: 26, nw: 22}}, + 23: {exits: [10]int{east: 22, west: 28, up: 24}}, + 24: {exits: [10]int{ne: 25, down: 23, nw: 28, sw: 26}}, + 25: {exits: [10]int{sw: 24}}, // Grating room (up to Clearing) + 26: {exits: [10]int{west: 16, sw: 24, east: 28, up: 22, north: 27}}, + 27: {exits: [10]int{south: 26}}, // Dead End + 28: {exits: [10]int{east: 22, down: 26, south: 23, west: 24}}, + 29: {exits: [10]int{west: 30, nw: 29, ne: 19, south: 19}}, + 30: {exits: [10]int{west: 29, south: 19}}, // ne to Cyclops Room +} + +func TestShortestPath() { + // The Zork maze is not a proper undirected simple graph, + // as there are some one way paths (e.g., 19 -> 15), + // but for this test that doesn't matter. + + // Set the index field in the map. Simpler than doing it in the + // composite literal. + for k := range zork { + r := zork[k] + r.index = k + zork[k] = r + } + + var nodes []mazeRoom + for idx, room := range zork { + mridx := room + mridx.index = idx + nodes = append(nodes, mridx) + } + g := _New[mazeRoom, mazeEdge](nodes) + path, err := g.ShortestPath(zork[11], zork[30]) + if err != nil { + panic(fmt.Sprintf("%v", err)) + } + var steps []direction + for _, edge := range path { + steps = append(steps, edge.dir) + } + want := []direction{east, west, up, sw, east, south} + if !_SliceEqual(steps, want) { + panic(fmt.Sprintf("ShortestPath returned %v, want %v", steps, want)) + } +} + +func main() { + TestShortestPath() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/ifaceconv.go b/platform/dbops/binaries/go/go/test/typeparam/ifaceconv.go new file mode 100644 index 0000000000000000000000000000000000000000..4dfc68f6e4e71efa1a3b8200c0d255233f0707e2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/ifaceconv.go @@ -0,0 +1,83 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that we can convert type parameters to both empty +// and nonempty interfaces, and named and nonnamed versions +// thereof. + +package main + +import "fmt" + +type E interface{} + +func f[T any](x T) interface{} { + var i interface{} = x + return i +} + +func fs[T any](x T) interface{} { + y := []T{x} + var i interface{} = y + return i +} + +func g[T any](x T) E { + var i E = x + return i +} + +type C interface { + foo() int +} + +type myInt int + +func (x myInt) foo() int { + return int(x + 1) +} + +func h[T C](x T) interface{ foo() int } { + var i interface{ foo() int } = x + return i +} +func i[T C](x T) C { + var i C = x // conversion in assignment + return i +} + +func j[T C](t T) C { + return C(t) // explicit conversion +} + +func js[T any](x T) interface{} { + y := []T{x} + return interface{}(y) +} + +func main() { + if got, want := f[int](7), 7; got != want { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := fs[int](7), []int{7}; got.([]int)[0] != want[0] { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := g[int](7), 7; got != want { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := h[myInt](7).foo(), 8; got != want { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := i[myInt](7).foo(), 8; got != want { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := j[myInt](7).foo(), 8; got != want { + panic(fmt.Sprintf("got %d want %d", got, want)) + } + if got, want := js[int](7), []int{7}; got.([]int)[0] != want[0] { + panic(fmt.Sprintf("got %d want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/importtest.go b/platform/dbops/binaries/go/go/test/typeparam/importtest.go new file mode 100644 index 0000000000000000000000000000000000000000..a49dcd9ba149952b0e05fec047414bec8997eba6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/importtest.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file checks that basic importing works in -G mode. + +package p + +import "fmt" +import "math" + +func f(x float64) { + fmt.Println(math.Sin(x)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/index.go b/platform/dbops/binaries/go/go/test/typeparam/index.go new file mode 100644 index 0000000000000000000000000000000000000000..064d33cfe747b4f92e21d87f9d93207304eddd43 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/index.go @@ -0,0 +1,81 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +// Index returns the index of x in s, or -1 if not found. +func Index[T comparable](s []T, x T) int { + for i, v := range s { + // v and x are type T, which has the comparable + // constraint, so we can use == here. + if v == x { + return i + } + } + return -1 +} + +type obj struct { + x int +} + +type obj2 struct { + x int8 + y float64 +} + +type obj3 struct { + x int64 + y int8 +} + +type inner struct { + y int64 + z int32 +} + +type obj4 struct { + x int32 + s inner +} + +func main() { + want := 2 + + vec1 := []string{"ab", "cd", "ef"} + if got := Index(vec1, "ef"); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + vec2 := []byte{'c', '6', '@'} + if got := Index(vec2, '@'); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + vec3 := []*obj{&obj{2}, &obj{42}, &obj{1}} + if got := Index(vec3, vec3[2]); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + vec4 := []obj2{obj2{2, 3.0}, obj2{3, 4.0}, obj2{4, 5.0}} + if got := Index(vec4, vec4[2]); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + vec5 := []obj3{obj3{2, 3}, obj3{3, 4}, obj3{4, 5}} + if got := Index(vec5, vec5[2]); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + vec6 := []obj4{obj4{2, inner{3, 4}}, obj4{3, inner{4, 5}}, obj4{4, inner{5, 6}}} + if got := Index(vec6, vec6[2]); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/index2.go b/platform/dbops/binaries/go/go/test/typeparam/index2.go new file mode 100644 index 0000000000000000000000000000000000000000..ae1b44a0e4b212d4cda4edaa9dd78c746dea0ec7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/index2.go @@ -0,0 +1,67 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Testing various generic uses of indexing, both for reads and writes. + +package main + +import "fmt" + +// Can index an argument (read/write) constrained to be a slice or an array. +func Index1[T interface{ []int64 | [5]int64 }](x T) int64 { + x[2] = 5 + return x[3] +} + +// Can index an argument (read) constrained to be a byte array or a string. +func Index2[T interface{ []byte | string }](x T) byte { + return x[3] +} + +// Can index an argument (write) constrained to be a byte array, but not a string. +func Index2a[T interface{ []byte }](x T) byte { + x[2] = 'b' + return x[3] +} + +// Can index an argument (read/write) constrained to be a map. Maps can't +// be combined with any other type for indexing purposes. +func Index3[T interface{ map[int]int64 }](x T) int64 { + x[2] = 43 + return x[3] +} + +// But the type of the map keys or values can be parameterized. +func Index4[T any](x map[int]T) T { + var zero T + x[2] = zero + return x[3] +} + +func test[T comparable](got, want T) { + if got != want { + panic(fmt.Sprintf("got %v, want %v", got, want)) + } +} + +func main() { + x := make([]int64, 4) + x[3] = 2 + y := [5]int64{1, 2, 3, 4, 5} + z := "abcd" + w := make([]byte, 4) + w[3] = 5 + v := make(map[int]int64) + v[3] = 18 + + test(Index1(x), int64(2)) + test(Index1(y), int64(4)) + test(Index2(z), byte(100)) + test(Index2(w), byte(5)) + test(Index2a(w), byte(5)) + test(Index3(v), int64(18)) + test(Index4(v), int64(18)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/interfacearg.go b/platform/dbops/binaries/go/go/test/typeparam/interfacearg.go new file mode 100644 index 0000000000000000000000000000000000000000..0e1fd0075deae9432a4910bec2d0c949fe739789 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/interfacearg.go @@ -0,0 +1,46 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface{} + +type _S[T any] struct { + x *T +} + +// F is a non-generic function, but has a type _S[I] which is instantiated from a +// generic type. Test that _S[I] is successfully exported. +func F() { + v := _S[I]{} + if v.x != nil { + panic(v) + } +} + +// Testing the various combinations of method expressions. +type S1 struct{} + +func (*S1) M() {} + +type S2 struct{} + +func (S2) M() {} + +func _F1[T interface{ M() }](t T) { + _ = T.M +} + +func F2() { + _F1(&S1{}) + _F1(S2{}) + _F1(&S2{}) +} + +func main() { + F() + F2() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue23536.go b/platform/dbops/binaries/go/go/test/typeparam/issue23536.go new file mode 100644 index 0000000000000000000000000000000000000000..1d6d79b4292aa19678f9e3b81c5218f94f52400d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue23536.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case where a slice of a user-defined byte type (not uint8 or byte) is +// converted to a string. Same for slice of runes. + +package main + +type MyByte byte + +type MyRune rune + +func f[T []MyByte](x T) string { + return string(x) +} + +func g[T []MyRune](x T) string { + return string(x) +} + +func main() { + var y []MyByte + _ = f(y) + _ = string(y) + + var z []MyRune + _ = g(z) + _ = string(z) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue376214.go b/platform/dbops/binaries/go/go/test/typeparam/issue376214.go new file mode 100644 index 0000000000000000000000000000000000000000..269b684b50843da2378db510006a60543273ff84 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue376214.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func add[S ~string | ~[]byte](buf *[]byte, s S) { + *buf = append(*buf, s...) +} + +func main() { + var buf []byte + add(&buf, "foo") + add(&buf, []byte("bar")) + if string(buf) != "foobar" { + panic("got " + string(buf)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue39755.go b/platform/dbops/binaries/go/go/test/typeparam/issue39755.go new file mode 100644 index 0000000000000000000000000000000000000000..52c7e7c6527c1856ca7fcfcc41192975fb6d4e85 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue39755.go @@ -0,0 +1,27 @@ +// compile + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// copied from cmd/compile/internal/types2/testdata/fixedbugs/issue39755.go + +package p + +func _[T interface{ ~map[string]int }](x T) { + _ = x == nil +} + +// simplified test case from issue + +type PathParamsConstraint interface { + ~map[string]string | ~[]struct{ key, value string } +} + +type PathParams[T PathParamsConstraint] struct { + t T +} + +func (pp *PathParams[T]) IsNil() bool { + return pp.t == nil // this must succeed +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue42758.go b/platform/dbops/binaries/go/go/test/typeparam/issue42758.go new file mode 100644 index 0000000000000000000000000000000000000000..25fb85ffb6dd75583b19d8d59d6d9e6c1e915e37 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue42758.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func F[T, U int]() interface{} { + switch interface{}(nil) { + case int(0), T(0), U(0): + } + + return map[interface{}]int{int(0): 0, T(0): 0, U(0): 0} +} + +func main() { + F[int, int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue44688.go b/platform/dbops/binaries/go/go/test/typeparam/issue44688.go new file mode 100644 index 0000000000000000000000000000000000000000..48160e07303ce6b2571956c3856e49665b8647a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue44688.go @@ -0,0 +1,149 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// derived & expanded from cmd/compile/internal/types2/testdata/fixedbugs/issue44688.go2 + +package main + +type A1[T any] struct { + val T +} + +func (p *A1[T]) m1(val T) { + p.val = val +} + +type A2[T any] interface { + m2(T) +} + +type B1[T any] struct { + filler int + *A1[T] + A2[T] +} + +type B2[T any] interface { + A2[T] +} + +type ImpA2[T any] struct { + f T +} + +func (a2 *ImpA2[T]) m2(s T) { + a2.f = s +} + +type C[T any] struct { + filler1 int + filler2 int + B1[T] +} + +type D[T any] struct { + filler1 int + filler2 int + filler3 int + C[T] +} + +func test1[T any](arg T) { + // calling embedded methods + var b1 B1[T] + b1.A1 = &A1[T]{} + b1.A2 = &ImpA2[T]{} + + b1.A1.m1(arg) + b1.m1(arg) + + b1.A2.m2(arg) + b1.m2(arg) + + var b2 B2[T] + b2 = &ImpA2[T]{} + b2.m2(arg) + + // a deeper nesting + var d D[T] + d.C.B1.A1 = &A1[T]{} + d.C.B1.A2 = &ImpA2[T]{} + d.m1(arg) + d.m2(arg) + + // calling method expressions + m1x := B1[T].m1 + m1x(b1, arg) + // TODO(khr): reenable these. + //m2x := B2[T].m2 + //m2x(b2, arg) + + // calling method values + m1v := b1.m1 + m1v(arg) + m2v := b1.m2 + m2v(arg) + b2v := b2.m2 + b2v(arg) +} + +func test2() { + // calling embedded methods + var b1 B1[string] + b1.A1 = &A1[string]{} + b1.A2 = &ImpA2[string]{} + + b1.A1.m1("") + b1.m1("") + + b1.A2.m2("") + b1.m2("") + + var b2 B2[string] + b2 = &ImpA2[string]{} + b2.m2("") + + // a deeper nesting + var d D[string] + d.C.B1.A1 = &A1[string]{} + d.C.B1.A2 = &ImpA2[string]{} + d.m1("") + d.m2("") + + // calling method expressions + m1x := B1[string].m1 + m1x(b1, "") + m2x := B2[string].m2 + m2x(b2, "") + + // calling method values + m1v := b1.m1 + m1v("") + m2v := b1.m2 + m2v("") + b2v := b2.m2 + b2v("") +} + +// actual test case from issue + +type A[T any] struct{} + +func (*A[T]) f(T) {} + +type B[T any] struct{ A[T] } + +func test3() { + var b B[string] + b.A.f("") + b.f("") +} + +func main() { + test1[string]("") + test2() + test3() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue45547.go b/platform/dbops/binaries/go/go/test/typeparam/issue45547.go new file mode 100644 index 0000000000000000000000000000000000000000..0024f364ba85c7377d4462e99da9e883bf51b2a4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue45547.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f[T any]() (f, g T) { return f, g } + +// Tests for generic function instantiation on the right hande side of multi-value +// assignments. + +func g() { + // Multi-value assignment within a function + var _, _ = f[int]() +} + +// Multi-value assignment outside a function. +var _, _ = f[int]() diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue45722.go b/platform/dbops/binaries/go/go/test/typeparam/issue45722.go new file mode 100644 index 0000000000000000000000000000000000000000..52a3c6359f911524c378fe6835408c0145c9c3f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue45722.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "log" +) + +func try[T any](v T, err error) T { + if err != nil { + panic(err) + } + return v +} + +func handle(handle func(error)) { + if issue := recover(); issue != nil { + if e, ok := issue.(error); ok && e != nil { + handle(e) + } else { + handle(fmt.Errorf("%v", e)) + } + } +} + +func main() { + defer handle(func(e error) { log.Fatalln(e) }) + _ = try(fmt.Print("")) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue45738.go b/platform/dbops/binaries/go/go/test/typeparam/issue45738.go new file mode 100644 index 0000000000000000000000000000000000000000..89b3b11ddef54aeee3bd8009c0f61cfd60edf36c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue45738.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +//go:noinline +func f[T any]() { + x := 5 + g := func() int { return x } + g() +} + +func main() { + f[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue45817.go b/platform/dbops/binaries/go/go/test/typeparam/issue45817.go new file mode 100644 index 0000000000000000000000000000000000000000..78e472f36a446c35b9dcef6e32d3d2f68d8cdb18 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue45817.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type s[T any] struct { + a T +} + +func (x s[T]) f() T { + return x.a +} +func main() { + x := s[int]{a: 7} + f := x.f + if got, want := f(), 7; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue46461.go b/platform/dbops/binaries/go/go/test/typeparam/issue46461.go new file mode 100644 index 0000000000000000000000000000000000000000..363a87cfe08f10ed145120369ab0a01fc7f13fee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue46461.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T[U interface{ M() T[U] }] int // ERROR "invalid recursive type: T refers to itself" + +type X int + +func (X) M() T[X] { return 0 } diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue46461b.go b/platform/dbops/binaries/go/go/test/typeparam/issue46461b.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue46461b.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue46472.go b/platform/dbops/binaries/go/go/test/typeparam/issue46472.go new file mode 100644 index 0000000000000000000000000000000000000000..027a8aaec1eedf907c0d2b1f58aea0131fe057cd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue46472.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func foo[T any](d T) { + switch v := interface{}(d).(type) { + case string: + if v != "x" { + panic("unexpected v: " + v) + } + } + +} +func main() { + foo("x") +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue46591.go b/platform/dbops/binaries/go/go/test/typeparam/issue46591.go new file mode 100644 index 0000000000000000000000000000000000000000..9e2c31de5d0d0ab6a54ac286dc40365f1cee8e6a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue46591.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T[_ any] struct{} + +var m = map[interface{}]int{ + T[struct{ int }]{}: 0, + T[struct { + int "x" + }]{}: 0, +} + +func main() { + if len(m) != 2 { + panic(len(m)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47258.go b/platform/dbops/binaries/go/go/test/typeparam/issue47258.go new file mode 100644 index 0000000000000000000000000000000000000000..7b202c93df8af675eb7922dd7fe55dbdc908a60b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47258.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Numeric interface { + int32 | int64 | float64 | complex64 +} + +//go:noline +func inc[T Numeric](x T) T { + x++ + return x +} +func main() { + if got, want := inc(int32(5)), int32(6); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := inc(float64(5)), float64(6.0); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := inc(complex64(5)), complex64(6.0); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47272.go b/platform/dbops/binaries/go/go/test/typeparam/issue47272.go new file mode 100644 index 0000000000000000000000000000000000000000..79748ad1aa091fc768a108adf9a00bf5143d11d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47272.go @@ -0,0 +1,55 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "errors" + "fmt" +) + +type Option[T any] struct { + ok bool + val T +} + +func (o Option[T]) String() string { + if o.ok { + return fmt.Sprintf("Some(%v)", o.val) + } + return "None" +} + +func Some[T any](val T) Option[T] { return Option[T]{ok: true, val: val} } +func None[T any]() Option[T] { return Option[T]{ok: false} } + +type Result[T, E any] struct { + ok bool + val T + err E +} + +func (r Result[T, E]) String() string { + if r.ok { + return fmt.Sprintf("Ok(%v)", r.val) + } + return fmt.Sprintf("Err(%v)", r.err) +} + +func Ok[T, E any](val T) Result[T, E] { return Result[T, E]{ok: true, val: val} } +func Err[T, E any](err E) Result[T, E] { return Result[T, E]{ok: false, err: err} } + +func main() { + a := Some[int](1) + b := None[int]() + fmt.Println(a, b) + + x := Ok[int, error](1) + y := Err[int, error](errors.New("test")) + fmt.Println(x, y) + // fmt.Println(x) + _, _, _, _ = a, b, x, y +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47272.out b/platform/dbops/binaries/go/go/test/typeparam/issue47272.out new file mode 100644 index 0000000000000000000000000000000000000000..9c433faa9701c4ea915826ba37788b958265d849 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47272.out @@ -0,0 +1,2 @@ +Some(1) None +Ok(1) Err(test) diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47514.go b/platform/dbops/binaries/go/go/test/typeparam/issue47514.go new file mode 100644 index 0000000000000000000000000000000000000000..1fc054ec356c1a01dbdfcfc768c3ca09200b46a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47514.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that closures inside a generic function are not exported, +// even though not themselves generic. + +package main + +func Do[T any]() { + _ = func() string { + return "" + } +} + +func main() { + Do[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47514b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47514b.go new file mode 100644 index 0000000000000000000000000000000000000000..0609296501873bd850013bf2ef55b4fd09d5b64e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47514b.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func Do[T any](do func() (T, string)) { + _ = func() (T, string) { + return do() + } +} + +func main() { + Do[int](func() (int, string) { + return 3, "3" + }) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47514c.go b/platform/dbops/binaries/go/go/test/typeparam/issue47514c.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47514c.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47631.go b/platform/dbops/binaries/go/go/test/typeparam/issue47631.go new file mode 100644 index 0000000000000000000000000000000000000000..32fd837ddd3ff07a6ddea1d36c8b70dc314ba986 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47631.go @@ -0,0 +1,31 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func g[T any]() { + type U []T + type V []int +} + +type S[T any] struct { +} + +func (s S[T]) m() { + type U []T + type V []int +} + +func f() { + type U []int +} + +type X struct { +} + +func (x X) m() { + type U []int +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47676.go b/platform/dbops/binaries/go/go/test/typeparam/issue47676.go new file mode 100644 index 0000000000000000000000000000000000000000..8569378cd67998c9839f609874ff6fa316354cb1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47676.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + d := diff([]int{}, func(int) string { + return "foo" + }) + d() +} + +func diff[T any](previous []T, uniqueKey func(T) string) func() { + return func() { + newJSON := map[string]T{} + for _, prev := range previous { + delete(newJSON, uniqueKey(prev)) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47684.go b/platform/dbops/binaries/go/go/test/typeparam/issue47684.go new file mode 100644 index 0000000000000000000000000000000000000000..f0e4ed05de3c2d0c0ea97242873b86d12b5559a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47684.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[G any]() int { + return func() int { + return func() int { + return 0 + }() + }() +} + +func main() { + f[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47684b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47684b.go new file mode 100644 index 0000000000000000000000000000000000000000..3e9fa93f34f6f36bb64836f76112a0f8797fe62c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47684b.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[G any]() interface{} { + return func() interface{} { + return func() interface{} { + var x G + return x + }() + }() +} + +func main() { + x := f[int]() + if v, ok := x.(int); !ok || v != 0 { + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47684c.go b/platform/dbops/binaries/go/go/test/typeparam/issue47684c.go new file mode 100644 index 0000000000000000000000000000000000000000..b1d45202f09a0b6faf3ce02339f502a95efcbb54 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47684c.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[G any]() func()func()int { + return func() func()int { + return func() int { + return 0 + } + } +} + +func main() { + f[int]()()() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47708.go b/platform/dbops/binaries/go/go/test/typeparam/issue47708.go new file mode 100644 index 0000000000000000000000000000000000000000..d6140f3b4fd7aa7137a055e6406382f6ec4570c2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47708.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type FooType[T any] interface { + Foo(BarType[T]) string +} +type BarType[T any] interface { + Bar(FooType[T]) string +} + +// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). +// type Baz[T any] T +// func (l Baz[T]) Foo(v BarType[T]) string { +// return v.Bar(l) +// } +// type Bob[T any] T +// func (l Bob[T]) Bar(v FooType[T]) string { +// if v,ok := v.(Baz[T]);ok{ +// return fmt.Sprintf("%v%v",v,l) +// } +// return "" +// } + +func main() { + // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). + // var baz Baz[int] = 123 + // var bob Bob[int] = 456 + // + // if got, want := baz.Foo(bob), "123456"; got != want { + // panic(fmt.Sprintf("got %s want %s", got, want)) + // } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47710.go b/platform/dbops/binaries/go/go/test/typeparam/issue47710.go new file mode 100644 index 0000000000000000000000000000000000000000..2263c8b88fd81769f9001290d0777f2668f2a0c7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47710.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type FooType[t any] interface { + Foo(BarType[t]) +} +type BarType[t any] interface { + Int(IntType[t]) FooType[int] +} + +type IntType[t any] int + +func (n IntType[t]) Foo(BarType[t]) {} +func (n IntType[_]) String() {} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47713.go b/platform/dbops/binaries/go/go/test/typeparam/issue47713.go new file mode 100644 index 0000000000000000000000000000000000000000..7e3b5a5d322fb8ff13d9781cd1e65aa9a83d094d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47713.go @@ -0,0 +1,52 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "encoding" + "fmt" +) + +type Seralizable interface { + encoding.BinaryMarshaler + encoding.BinaryUnmarshaler +} + +type SerDeString string + +func (s *SerDeString) UnmarshalBinary(in []byte) error { + *s = SerDeString(in) + return nil +} + +func (s SerDeString) MarshalBinary() ([]byte, error) { + return []byte(s), nil +} + + +type GenericSerializable[T Seralizable] struct { + Key string + Value T +} + +func (g GenericSerializable[T]) Send() { + out, err := g.Value.MarshalBinary() + if err != nil { + panic("bad") + } + var newval SerDeString + newval.UnmarshalBinary(out) + fmt.Printf("Sent %s\n", newval) +} + +func main() { + val := SerDeString("asdf") + x := GenericSerializable[*SerDeString]{ + Value: &val, + } + x.Send() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47713.out b/platform/dbops/binaries/go/go/test/typeparam/issue47713.out new file mode 100644 index 0000000000000000000000000000000000000000..a6e77197d81c62f4fae6cdb17dcc962ebbca3aca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47713.out @@ -0,0 +1 @@ +Sent asdf diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47716.go b/platform/dbops/binaries/go/go/test/typeparam/issue47716.go new file mode 100644 index 0000000000000000000000000000000000000000..5024ac9b7346fef5d75f466721a84a33c3546d68 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47716.go @@ -0,0 +1,68 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "unsafe" +) + +// size returns the size of type T +func size[T any](x T) uintptr { + return unsafe.Sizeof(x) +} + +// size returns the alignment of type T +func align[T any](x T) uintptr { + return unsafe.Alignof(x) +} + +type Tstruct[T any] struct { + f1 T + f2 int +} + +// offset returns the offset of field f2 in the generic type Tstruct +func (r *Tstruct[T]) offset() uintptr { + return unsafe.Offsetof(r.f2) +} + +func main() { + v1 := int(5) + if got, want := size(v1), unsafe.Sizeof(v1); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := align(v1), unsafe.Alignof(v1); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + v2 := "abc" + if got, want := size(v2), unsafe.Sizeof(v2); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := align(v2), unsafe.Alignof(v2); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + var v3 Tstruct[int] + if got, want := unsafe.Offsetof(v3.f2), unsafe.Sizeof(v1); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + var v4 Tstruct[interface{}] + var v5 interface{} + if got, want := unsafe.Offsetof(v4.f2), unsafe.Sizeof(v5); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got, want := v3.offset(), unsafe.Offsetof(v3.f2); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := v4.offset(), unsafe.Offsetof(v4.f2); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47723.go b/platform/dbops/binaries/go/go/test/typeparam/issue47723.go new file mode 100644 index 0000000000000000000000000000000000000000..44c55b6145af5551ca7cbe62bc5e63c0cb52227f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47723.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[_ any]() int { + var a [1]int + _ = func() int { + return func() int { + return 0 + }() + }() + return a[func() int { + return 0 + }()] +} + +func main() { + f[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47740.go b/platform/dbops/binaries/go/go/test/typeparam/issue47740.go new file mode 100644 index 0000000000000000000000000000000000000000..f34394ce36ea6c5ecf1ff27bf13c96c49a53ce27 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47740.go @@ -0,0 +1,40 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type Exp[Ty any] interface { + Eval() Ty +} + +// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). +// type Lit[Ty any] Ty +// +// func (lit Lit[Ty]) Eval() Ty { return Ty(lit) } +// func (lit Lit[Ty]) String() string { return fmt.Sprintf("(lit %v)", Ty(lit)) } + +type Eq[Ty any] struct { + a Exp[Ty] + b Exp[Ty] +} + +func (e Eq[Ty]) String() string { + return fmt.Sprintf("(eq %v %v)", e.a, e.b) +} + +// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). +// var ( +// e0 = Eq[int]{Lit[int](128), Lit[int](64)} +// e1 = Eq[bool]{Lit[bool](true), Lit[bool](true)} +// ) + +func main() { + // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). + // fmt.Printf("%v\n", e0) + // fmt.Printf("%v\n", e1) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47740.out b/platform/dbops/binaries/go/go/test/typeparam/issue47740.out new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47740b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47740b.go new file mode 100644 index 0000000000000000000000000000000000000000..d46d05802eb4cdf6667e61a2e2fae70ed085bcd1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47740b.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "reflect" + +type S[T any] struct { + a interface{} +} + +func (e S[T]) M() { + v := reflect.ValueOf(e.a) + _, _ = v.Interface().(int) +} + +func main() { + e := S[int]{0} + e.M() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47775.go b/platform/dbops/binaries/go/go/test/typeparam/issue47775.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47775.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47775b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47775b.go new file mode 100644 index 0000000000000000000000000000000000000000..e084e0316f3abbbf95518deca26da25a24a94005 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47775b.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type C[T any] struct { +} + +func (c *C[T]) reset() { +} + +func New[T any]() { + c := &C[T]{} + i = c.reset + z(c.reset) +} + +var i interface{} + +func z(interface{}) { +} + +func main() { + New[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47797.go b/platform/dbops/binaries/go/go/test/typeparam/issue47797.go new file mode 100644 index 0000000000000000000000000000000000000000..ad89bcce01213b562deb0404dbf0ae7fac448067 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47797.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Foo[T any] struct { + Val T +} + +func (f Foo[T]) Bat() {} + +type Bar struct { + Foo[int] +} + +func foo() { + var b Bar + b.Bat() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47877.go b/platform/dbops/binaries/go/go/test/typeparam/issue47877.go new file mode 100644 index 0000000000000000000000000000000000000000..be5c5c08f6dc8c87009e5a703fd588543bd7b0a2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47877.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Map[K comparable, V any] struct { + m map[K]V +} + +func NewMap[K comparable, V any]() Map[K, V] { + return Map[K, V]{m: map[K]V{}} +} + +func (m Map[K, V]) Get(key K) V { + return m.m[key] +} + +func main() { + _ = NewMap[int, struct{}]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47878.go b/platform/dbops/binaries/go/go/test/typeparam/issue47878.go new file mode 100644 index 0000000000000000000000000000000000000000..25758cbe9097c406e87742f3ca8c50ed261a10e4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47878.go @@ -0,0 +1,56 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Src1[T any] func() Src1[T] + +func (s *Src1[T]) Next() { + *s = (*s)() +} + +type Src2[T any] []func() Src2[T] + +func (s Src2[T]) Next() { + _ = s[0]() +} + +type Src3[T comparable] map[T]func() Src3[T] + +func (s Src3[T]) Next() { + var a T + _ = s[a]() +} + +type Src4[T any] chan func() T + +func (s Src4[T]) Next() { + _ = (<-s)() +} + +type Src5[T any] func() Src5[T] + +func (s Src5[T]) Next() { + var x interface{} = s + _ = (x.(Src5[T]))() +} + +func main() { + var src1 Src1[int] + src1.Next() + + var src2 Src2[int] + src2.Next() + + var src3 Src3[string] + src3.Next() + + var src4 Src4[int] + src4.Next() + + var src5 Src5[int] + src5.Next() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47892.go b/platform/dbops/binaries/go/go/test/typeparam/issue47892.go new file mode 100644 index 0000000000000000000000000000000000000000..5bb6a746b3fd89d1a227c2ff7783a8efe904fe46 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47892.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47892b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47892b.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47892b.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47896.go b/platform/dbops/binaries/go/go/test/typeparam/issue47896.go new file mode 100644 index 0000000000000000000000000000000000000000..616e90714b99a8d12fb20e856a8a7d061dcaa155 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47896.go @@ -0,0 +1,74 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "database/sql" +) + +// Collection generic interface which things can be added to. +type Collection[T any] interface { + Add(T) +} + +// Slice generic slice implementation of a Collection +type Slice[T any] []*T + +func (s *Slice[T]) Add(t *T) { + *s = append(*s, t) +} + +type Scanner interface { + Scan(...interface{}) error +} + +type Mapper[T any] func(s Scanner, t T) error + +type Repository[T any] struct { + db *sql.DB +} + +func (r *Repository[T]) scan(rows *sql.Rows, m Mapper[*T], c Collection[*T]) error { + for rows.Next() { + t := new(T) + if err := m(rows, t); err != nil { + return err + } + c.Add(t) + } + return rows.Err() +} + +func (r *Repository[T]) query(query string, m Mapper[*T], c Collection[*T]) error { + rows, err := r.db.Query(query) + if err != nil { + return err + } + if err := r.scan(rows, m, c); err != nil { + rows.Close() + return err + } + return rows.Close() +} + +type Actor struct { + ActorID uint16 + FirstName string + LastName string +} + +type ActorRepository struct { + r Repository[Actor] +} + +func (ActorRepository) scan(s Scanner, a *Actor) error { + return s.Scan(&a.ActorID, &a.FirstName, &a.LastName) +} + +func (r *ActorRepository) SelectAll(c Collection[*Actor]) error { + return r.r.query("SELECT `actor_id`, `first_name`, `last_name` FROM `actor` LIMIT 10", r.scan, c) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47901.go b/platform/dbops/binaries/go/go/test/typeparam/issue47901.go new file mode 100644 index 0000000000000000000000000000000000000000..e005135185445d4aadf7f79000c4d255e375f0ea --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47901.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Chan[T any] chan Chan[T] + +func (ch Chan[T]) recv() Chan[T] { + return <-ch +} + +func main() { + ch := Chan[int](make(chan Chan[int])) + go func() { + ch <- make(Chan[int]) + }() + ch.recv() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47924.go b/platform/dbops/binaries/go/go/test/typeparam/issue47924.go new file mode 100644 index 0000000000000000000000000000000000000000..eea7acbdf00e43ecb9b36ae6b8a7f3680adfc71a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47924.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Cache[K any] struct{} + +func (c Cache[K]) foo(x interface{}, f func(K) bool) { + f(x.(K)) +} + +var _ Cache[int] diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47925.go b/platform/dbops/binaries/go/go/test/typeparam/issue47925.go new file mode 100644 index 0000000000000000000000000000000000000000..c595e14a6fe22d65ae95a53146093962dd901f8a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47925.go @@ -0,0 +1,20 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type myifacer[T any] interface{ do(T) error } + +type stuff[T any] struct{} + +func (s stuff[T]) run() interface{} { + var i myifacer[T] + return i +} + +func main() { + stuff[int]{}.run() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47925b.go b/platform/dbops/binaries/go/go/test/typeparam/issue47925b.go new file mode 100644 index 0000000000000000000000000000000000000000..bffbe4e3d44e001de642d6630c6863720de2951e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47925b.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I[T any] interface { + foo() +} + +type E[T any] interface { +} + +//go:noinline +func f[T I[T]](x T) E[T] { + // contains a cast from nonempty to empty interface + return E[T](I[T](x)) +} + +type S struct { + x int +} + +func (s *S) foo() {} + +func main() { + i := f(&S{x: 7}) + if i.(*S).x != 7 { + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47925c.go b/platform/dbops/binaries/go/go/test/typeparam/issue47925c.go new file mode 100644 index 0000000000000000000000000000000000000000..9636b9d10dc5e8146097a6f1cdab564847ec6e92 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47925c.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I[T any] interface { + foo() +} + +type J[T any] interface { + foo() + bar() +} + +//go:noinline +func f[T J[T]](x T) I[T] { + // contains a cast between two nonempty interfaces + return I[T](J[T](x)) +} + +type S struct { + x int +} + +func (s *S) foo() {} +func (s *S) bar() {} + +func main() { + i := f(&S{x: 7}) + if i.(*S).x != 7 { + panic("bad") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47925d.go b/platform/dbops/binaries/go/go/test/typeparam/issue47925d.go new file mode 100644 index 0000000000000000000000000000000000000000..c5647f9a5b060592586def05288778b317a4fdac --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47925d.go @@ -0,0 +1,47 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I[T any] interface { + foo() +} + +type J[T any] interface { + foo() + bar() +} + +//go:noinline +func f[T J[T]](x T, g func(T) T) I[T] { + // contains a cast between two nonempty interfaces + // Also make sure we don't evaluate g(x) twice. + return I[T](J[T](g(x))) +} + +type S struct { + x int +} + +func (s *S) foo() {} +func (s *S) bar() {} + +var cnt int + +func inc(s *S) *S { + cnt++ + return s +} + +func main() { + i := f(&S{x: 7}, inc) + if i.(*S).x != 7 { + panic("bad") + } + if cnt != 1 { + panic("multiple calls") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47929.go b/platform/dbops/binaries/go/go/test/typeparam/issue47929.go new file mode 100644 index 0000000000000000000000000000000000000000..1aa6885bdd404991980faae85682842479a84ec5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47929.go @@ -0,0 +1,29 @@ +// compile -p=p + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package v4 + +var sink interface{} + +//go:noinline +func Do(result, body interface{}) { + sink = &result +} + +func DataAction(result DataActionResponse, body DataActionRequest) { + Do(&result, body) +} + +type DataActionRequest struct { + Action *interface{} +} + +type DataActionResponse struct { + ValidationErrors *ValidationError +} + +type ValidationError struct { +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47948.go b/platform/dbops/binaries/go/go/test/typeparam/issue47948.go new file mode 100644 index 0000000000000000000000000000000000000000..deab0efe57eb366a24dc1b820b43cded8f02959b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47948.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type fun func() + +func F[T any]() { + _ = fun(func() { + + }) +} +func main() { + F[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue47966.go b/platform/dbops/binaries/go/go/test/typeparam/issue47966.go new file mode 100644 index 0000000000000000000000000000000000000000..ec664783b099c02a96d1a959713706b10fbfe4b3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue47966.go @@ -0,0 +1,9 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type C comparable diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48013.go b/platform/dbops/binaries/go/go/test/typeparam/issue48013.go new file mode 100644 index 0000000000000000000000000000000000000000..3fbf2490df4580c0401b4d11c9fbaf00bb479625 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48013.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "unsafe" +) + +type S[T any] struct { + val T +} + +// Test type substitution where base type is unsafe.Pointer +type U[T any] unsafe.Pointer + +func test[T any]() T { + var q U[T] + var v struct { + // Test derived type that contains an unsafe.Pointer + p unsafe.Pointer + val T + } + _ = q + return v.val +} + +func main() { + want := 0 + got := test[int]() + if got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } + +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48016.go b/platform/dbops/binaries/go/go/test/typeparam/issue48016.go new file mode 100644 index 0000000000000000000000000000000000000000..dbc87eccba5555fe5a8fabf1c9abb24d02df1907 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48016.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "strconv" +) + +func test1[T any](fn func(T) int, v T) int { + fn1 := func() int { + var i interface{} = v + val := fn(i.(T)) + return val + } + return fn1() +} + +func main() { + want := 123 + got := test1(func(s string) int { + r, err := strconv.Atoi(s) + if err != nil { + return 0 + } + return r + }, "123") + if got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48030.go b/platform/dbops/binaries/go/go/test/typeparam/issue48030.go new file mode 100644 index 0000000000000000000000000000000000000000..23494f90dbdf4e78209044ec832d07e79044772c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48030.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Src[T any] func() Src[T] + +func Seq[T any]() Src[T] { + return nil +} + +func Seq2[T1 any, T2 any](v1 T1, v2 T2) Src[T2] { + return nil +} + +func main() { + // Type args fully supplied + Seq[int]() + // Partial inference of type args + Seq2[int](5, "abc") + // Full inference of type args + Seq2(5, "abc") +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48042.go b/platform/dbops/binaries/go/go/test/typeparam/issue48042.go new file mode 100644 index 0000000000000000000000000000000000000000..1cfbfbe96ce7cfd31bdc6c3e64c2a9a1695822d4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48042.go @@ -0,0 +1,77 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "reflect" +) + +type G[T any] interface { + g() func()(*T) +} +type Foo[T any] struct { + +} +// OCALL +func (l *Foo[T]) f1() (*T) { + return g[T]()() +} +// OCALLFUNC +func (l *Foo[T]) f2() (*T) { + var f = g[T] + return f()() +} +// OCALLMETH +func (l *Foo[T]) f3() (*T) { + return l.g()() +} +// OCALLINTER +func (l *Foo[T]) f4() (*T) { + var g G[T] = l + return g.g()() +} +// ODYNAMICDOTTYPE +func (l *Foo[T]) f5() (*T) { + var x interface{} + x = g[T] + return x.(func()func()(*T))()() +} +func (l *Foo[T]) g() func() (*T) { + return func() (*T) { + t := new(T) + reflect.ValueOf(t).Elem().SetInt(100) + return t + } +} +func g[T any]() func() (*T) { + return func() (*T) { + t := new(T) + reflect.ValueOf(t).Elem().SetInt(100) + return t + } +} + +func main() { + foo := Foo[int]{} + // Make sure the function conversion is correct + if n := *(foo.f1()) ; n != 100{ + panic(fmt.Sprintf("%v",n)) + } + if n := *(foo.f2()) ; n != 100{ + panic(fmt.Sprintf("%v",n)) + } + if n := *(foo.f3()) ; n != 100{ + panic(fmt.Sprintf("%v",n)) + } + if n := *(foo.f4()) ; n != 100{ + panic(fmt.Sprintf("%v",n)) + } + if n := *(foo.f5()) ; n != 100{ + panic(fmt.Sprintf("%v",n)) + } +} \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48047.go b/platform/dbops/binaries/go/go/test/typeparam/issue48047.go new file mode 100644 index 0000000000000000000000000000000000000000..06a2ebdb3968d793c8f57669fc3781a433940241 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48047.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type A[T any] struct { + field B[T] +} + +type B[T any] interface { + Work(T) +} + +func (a *A[T]) Work(t T) { + a.field.Work(t) +} + +type BImpl struct{} + +func (b BImpl) Work(s string) {} + +func main() { + a := &A[string]{ + field: BImpl{}, + } + a.Work("") +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48049.go b/platform/dbops/binaries/go/go/test/typeparam/issue48049.go new file mode 100644 index 0000000000000000000000000000000000000000..3e87b387f013edbc92d674c537bc7ae40f8070a6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48049.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + Gooer2[byte]() +} + +type Fooer[T any] interface { + Foo(p T) +} + +type fooer1[T any] struct{} + +func (fooer1[T]) Foo(T) {} + +type fooer2[T any] struct { + r []Fooer[T] +} + +//go:noinline +func (mr fooer2[T]) Foo(p T) { + mr.r[0] = fooer1[T]{} + return +} + +func Gooer2[T any]() Fooer[T] { + return fooer2[T]{} +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48056.go b/platform/dbops/binaries/go/go/test/typeparam/issue48056.go new file mode 100644 index 0000000000000000000000000000000000000000..e91d689d2bb702e8a3d2b676ef34028de2bd73cc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48056.go @@ -0,0 +1,27 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type B[T any] interface { + Work() +} +type BImpl[T any] struct{} + +func (b *BImpl[T]) Work() { +} + +type A[T any] struct { + B[T] +} + +func f[T any]() { + s := &A[T]{ + &BImpl[T]{}, + } + // golang.org/issue/48056 + s.Work() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48094.go b/platform/dbops/binaries/go/go/test/typeparam/issue48094.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48094.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48094b.go b/platform/dbops/binaries/go/go/test/typeparam/issue48094b.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48094b.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48137.go b/platform/dbops/binaries/go/go/test/typeparam/issue48137.go new file mode 100644 index 0000000000000000000000000000000000000000..84a0f6db6f7ebb3d61797c8cc1e8509b5533313b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48137.go @@ -0,0 +1,25 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Constraint[T any] interface { + ~func() T +} + +func Foo[T Constraint[T]]() T { + var t T + + t = func() T { + return t + } + return t +} + +func main() { + type Bar func() Bar + Foo[Bar]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48185a.go b/platform/dbops/binaries/go/go/test/typeparam/issue48185a.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48185a.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48185b.go b/platform/dbops/binaries/go/go/test/typeparam/issue48185b.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48185b.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48191.go b/platform/dbops/binaries/go/go/test/typeparam/issue48191.go new file mode 100644 index 0000000000000000000000000000000000000000..9c3218b9fadf0388e29a702cbf2e3ab20a2d1382 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48191.go @@ -0,0 +1,269 @@ +// compile -c=2 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I1 interface { + int8 | int16 | int32 | int64 | int | uint +} +type I2 interface{ float32 | float64 } +type I3 interface{ string } + +func F[G1 I1, G2 I2, G3 I3]() { + var m0 map[G2]rune + var ch0, ch1 chan bool + var ast0, ast1 []struct{ s0 G3 } + var ai64_2 []int64 + var m1, m2, m3 map[bool]map[int]struct { + m0 map[G2]byte + s1 G3 + } + var i8_0, i8_1 G1 + var i16_0 int16 + var am3, am4 []map[float64]map[G2]*func(*byte, map[uint]int64, G3, struct{}) G2 + var pi64_0, pi64_1 *int64 + var i, i1, i2 int + var as5, as6, as7 []G3 + var ch2, ch3, ch4 chan uint + var m4, m5, m6 map[G1]chan bool + + if func(G2, int32) byte { + return m1[false][30].m0[G2(28.6)] * m3[func(bool, uint) bool { + return false + }(false, uint(94))][31].m0[G2(185.0)] * m1[(true || true) && (false && false)][51-i2].m0[G2(278.6)] + }(G2(672.5), int32(35)) < m3[<-m5[func(int64, int64) G1 { + return i8_1 + }(*pi64_0, int64(50))]][15&i1^i2^i2].m0[G2(895.3)] || (func(int64, uint) uint { + return uint(94) + }(int64(30), uint(95))&^<-ch2^<-ch4)&<-ch2^<-ch4 == <-ch2 { + var f0 float64 + var pf2 *float64 + var ch5, ch6 chan int16 + var fnc0 func(*int64, G2, struct { + i8_0 G1 + m1 map[float64]bool + i64_2 int64 + }, map[byte]func(G2, float64, *uint, float64) struct{}) complex128 = func(p0 *int64, p1 G2, p2 struct { + i8_0 G1 + m1 map[float64]bool + i64_2 int64 + }, p3 map[byte]func(G2, float64, *uint, float64) struct{}) complex128 { + p0 = pi64_1 + m5 = map[G1]chan bool{(p2.i8_0 + i8_1 + i8_1 ^ i8_1) * p2.i8_0 / p2.i8_0: m4[p2.i8_0>><-ch2]} + return (2.65i - 31.18i) * func(byte, byte) complex128 { + return 13.12i - 32.90i + (44.15i - 70.53i - (87.16i*92.67i + (24.18i - 9.13i))) + (func(G1, int16) complex128 { + return 55.80i + }(G1(30), int16(80)) + 8.48i*79.18i + (37.30i*73.81i + (21.01i - 76.30i)) + func(G3, G2) complex128 { + return 35.58i + }(G3("2JYizeFiEMvXLkUR"), p1)*(81.59i-21.76i)) + }(m1[<-m5[G1(37)*i8_1<= '4'&'\uab3e'>>uint(83) && (<-m6[G1(24)%i8_0] && <-ch1)][i].s1 + i = len([]G3{ast1[2].s0}) + i16_0 = <-ch6 / i16_0 & <-ch6 + i = (i1^i|i2|i2)/i + i + m6 = m4 + am3 = am3 + m1[G2(869.6) == G2(i2)] = m2[func(float64, rune) byte { + return func(G3, byte) byte { + return byte(42) + }(G3("8iDnlygG194xl"), byte(89)) + }(*pf2, '\u9cf4')/m1[func(G3, float64) bool { + return false + }(G3("6MbwBSHYzr9t0zD"), 774.4)][76].m0[G2(508.0)]/m2[<-m4[i8_0]][92&^i2].m0[G2(807.0)] > m3[(int32(39)|int32(i2))&^int32(i2) < int32(i2)][89*i1&i2].m0[G2(327.5)]] + m2[<-m4[func(G1, complex128) G1 { + return i8_1 + }(i8_0, 35.01i)] && <-m4[func(int, G1) G1 { + return G1(0) + }(10, G1(70))*i8_1&i8_1>><-ch2] || fnc0(pi64_0, G2(689.5), struct { + i8_0 G1 + m1 map[float64]bool + i64_2 int64 + }{(G1(78)*i8_1 - i8_1) / i8_1, map[float64]bool{499.2: <-m6[G1(88)^i8_0]}, int64(83) &^ ai64_2[33] & *pi64_1 * ai64_2[i1]}, map[byte]func(G2, float64, *uint, float64) struct { + }{m1[len(G3("bNIJZq")+G3("Fri5pn1MsZzYtsaV7b")) >= i][i^i1].m0[G2(691.7)]: nil}) != 71.77i-34.84i] = map[int]struct { + m0 map[G2]byte + s1 G3 + }{((18+i2)&^i2%i2 ^ i) / i: m3[(G2(267.1)*G2(i1) > G2(i2) || (false || true || (true || false))) && func(int32, int64) bool { + return <-ch0 + }(int32(63), ai64_2[61&^i1&i2])][i|i^i1]} + i2 = 90 - i1 + _, _, _, _, _, _, _, _ = f0, pf2, ch5, ch6, fnc0, m7, ch7, fnc1 + } else { + var m7 map[G1]chan uint + var ch5, ch6, ch7 chan G3 + var i32_0, i32_1 int32 + var m8, m9, m10 map[bool]struct { + } + pi64_1 = pi64_0 + m6[func(G3, G2) G1 { + return (G1(35) | i8_0) << i8_1 / i8_1 &^ i8_1 / i8_1 + }(G3("YBiKg"), G2(122.6))] = make(chan bool) + ast0 = ast0 + i8_1 = (((G1(10)+i8_1)&i8_0+i8_0)&i8_0&i8_1 ^ i8_1) & i8_1 + am4 = am3 + i32_1 = int32(10) &^ i32_0 + m8[func(float64, G3) bool { + return func(rune, int16) bool { + return (G2(267.0)*G2(i2) == G2(i) || func(G2, G3) bool { + return <-ch0 + }(G2(53.3), <-ch5)) && func(G2, G1) int32 { + return int32(63) + }(G2(804.8), G1(2))-i32_0 < i32_1 + }('\xbd', i16_0) + }(370.9, ast0[len([]complex128{})+i-i2].s0) && (G2(245.0)-G2(i1) == G2(i1) || byte(17)&m2[false][26].m0[G2(628.5)] > m3[false][55].m0[G2(608.8)] || func(G1, G1) bool { + return true + }(G1(24), G1(2)) || (<-m5[G1(38)] || <-ch1) && func(int32, int) bool { + return false && true + }(int32(6), i1) && '\x26'&'\x27'|func(G2, G3) rune { + return '\x13' + }(G2(229.6), G3("ys1msVeg61uSImCDkRG3C")) <= 'V'>>uint(88)-('\xbe'+'\uafd4')) == (53.04i == 37.22i)] = m8[func(byte, int64) bool { + return <-ch1 + }(m3[false && false][96].m0[G2(147.6)], *pi64_0) && 643.5 > float64(i1) && (<-ch0 && <-ch1)] + i8_1 = func(byte, uint) G1 { + return G1(68) + }(m2[<-ch1 || <-m5[G1(96)+i8_0] || func(bool, int32) bool { + return func(int, byte) bool { + return m1[true][89].s1 <= G3("2ZMnHGOMQnyHSbJ") + }(i2, m2[<-m6[G1(47)]][94].m0[G2(981.3)]) + }(<-m4[G1(0)&^i8_0&i8_0], i32_0)][i2%i&^i].m0[func(complex128, rune) G2 { + return G2(93.1) * G2(i2) + }(4.63i, m0[G2(975.8)])], uint(21)) + _, _, _, _, _, _, _, _, _ = m7, ch5, ch6, ch7, i32_0, i32_1, m8, m9, m10 + } + + if *pi64_0>><-ch3 <= *pi64_0 || func(bool, int32) int32 { + return (int32(69)&^int32(i2) + int32(i2)) * int32(i2) + }(true, int32(49))^int32(i2) >= int32(i) { + var ai8_8, ai8_9 []G1 + var pi2, pi3, pi4 *int + var pi8_5, pi8_6 *G1 + var i64_0, i64_1 int64 + m1[754.8*float64(i2) != float64(i) && 6.26i == 69.99i] = map[int]struct { + m0 map[G2]byte + s1 G3 + }{len([]G2{G2(935.9) / G2(i2), func(int64, G2) G2 { + return G2(720.5) + }(int64(36), G2(349.7))})&*pi2 + i2 - i1: m1[(uint(29) >= <-ch4 || int64(45)+ai64_2[18] >= *pi64_1) == (func(G2, G2) bool { + return <-m5[G1(25)] + }(G2(447.2), G2(946.6)) || func(int, int16) bool { + return true + }(40, int16(41)) && byte(51) >= m2[true][13].m0[G2(6.6)])][*pi3]} + am4 = []map[float64]map[G2]*func(*byte, map[uint]int64, G3, struct { + }) G2{am4[i2%*pi3]} + pi2 = &i2 + pi64_0 = pi64_1 + ai8_8[*pi3] = *pi8_5&ai8_9[(*pi4+*pi3)%*pi3] ^ ai8_8[90+i2|*pi4] + ai64_2 = []int64{} + m4 = m4 + pi2 = &i1 + pi3 = &i2 + _, _, _, _, _, _, _, _, _ = ai8_8, ai8_9, pi2, pi3, pi4, pi8_5, pi8_6, i64_0, i64_1 + } + + if (true || false || int32(68) > int32(i1) || <-m5[G1(11)-i8_0] && true) && func(int, float64) bool { + return <-m5[(G1(83)-i8_1)&^i8_1] + }(i1, 886.6) || func(byte, int) bool { + return 401.0/float64(i1)/float64(i1)-float64(i) == float64(i2) + }(m1[(G1(85)^i8_1)&^i8_1 <= i8_1][72].m0[G2(617.4)], i1) || (<-m6[(G1(3)|i8_0)>><-ch2%i8_0|i8_0] || <-ch0) { + var ch5 chan map[byte]complex128 + var fnc0 func(int32, *map[rune]complex128) complex128 + var c0 complex128 + var st0, st1, st2 struct { + } + var au8 []uint + var st3, st4, st5 struct { + ph0 *G2 + st1 struct { + m0 map[rune]complex128 + pch1 *chan int64 + m2 map[bool]byte + st3 struct { + ch0 chan func(map[G1]*struct { + pm0 *map[bool]int64 + h1 G2 + }, struct { + u0 uint + }, uint, float64) *struct { + ch0 chan map[int16]G2 + } + i1 int + ch2 chan complex128 + } + } + pm2 *map[int64]struct { + s0 G3 + pi1 *int + st2 struct { + m0 map[int]map[rune]int64 + r1 rune + } + } + } + var am9, am10, am11 []map[uint]int64 + m1[G3("E")+(*st4.pm2)[*pi64_0+<-*st3.st1.pch1].s0 < (*st4.pm2)[int64(46)].s0+(G3("4Jsp3pv0x")+G3("MTKt98c")+(G3("E6Nxqpl70")+G3("eXhhxb")))+(G3("siISQNeBXoQIHwGB")+G3("CzocwLRWIUD")+(G3("cDWy3E3qpeJOmw1wP9wZ")+G3("S3ZRONdtB7K1LBC"))+func(G1, uint) G3 { + return m2[false][74].s1 + }(G1(9), uint(26)))+func(G2, int) G3 { + return G3("WzncXvaqK4zPn") + }(G2(291.6), i)+(ast1[(40^i1+i1)&^st4.st1.st3.i1].s0+func(byte, int64) G3 { + return m2[207.7 == float64(i2) && (false || false)][i2].s1 + }(byte(34), am11[25][func(int32, float64) uint { + return uint(77) + }(int32(29), 403.1)]))] = map[int]struct { + m0 map[G2]byte + s1 G3 + }{st3.st1.st3.i1: m2[<-m4[i8_1]][st5.st1.st3.i1-st3.st1.st3.i1-i2]} + st1 = struct { + }{} + pi64_0 = pi64_1 + m4 = m6 + as7 = as7 + m6[(i8_0+i8_0)&^i8_1&^i8_1] = m5[G1(96)^i8_1] + st2 = struct { + }{} + st1 = struct { + }{} + am10 = []map[uint]int64{am9[len((*st4.pm2)[int64(65)].s0)+i], am11[st4.st1.st3.i1%st4.st1.st3.i1^i1]} + i2 = st5.st1.st3.i1*i - st5.st1.st3.i1 + _, _, _, _, _, _, _, _, _, _, _, _, _ = ch5, fnc0, c0, st0, st1, st2, au8, st3, st4, st5, am9, am10, am11 + } + +} + +func main() { + F[int16, float32, string]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48198.go b/platform/dbops/binaries/go/go/test/typeparam/issue48198.go new file mode 100644 index 0000000000000000000000000000000000000000..1ed29b89db159de760d57af9ab655d008a7d6de2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48198.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +package p + +type Foo[T any] struct { +} + +func (foo Foo[T]) Get() { +} + +var( + _ = Foo[byte]{} + _ = Foo[[]byte]{} + _ = Foo[map[byte]rune]{} + + _ = Foo[rune]{} + _ = Foo[[]rune]{} + _ = Foo[map[rune]byte]{} +) diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48225.go b/platform/dbops/binaries/go/go/test/typeparam/issue48225.go new file mode 100644 index 0000000000000000000000000000000000000000..702bc077994e3f76601474466f961a912df9e8e9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48225.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "reflect" + +type Foo[T any] struct { + val int +} + +func (foo Foo[T]) Get() *T { + if foo.val != 1 { + panic("bad val field in Foo receiver") + } + return new(T) +} + +var ( + newInt = Foo[int]{val: 1}.Get + newString = Foo[string]{val: 1}.Get +) + +func main() { + i := newInt() + s := newString() + + if t := reflect.TypeOf(i).String(); t != "*int" { + panic(t) + } + if t := reflect.TypeOf(s).String(); t != "*string" { + panic(t) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48253.go b/platform/dbops/binaries/go/go/test/typeparam/issue48253.go new file mode 100644 index 0000000000000000000000000000000000000000..20d5db662a313425aad06c6af1871420d3b6b547 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48253.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "reflect" +) + +type A[T any] struct { + B[int] +} + +type B[T any] struct { +} + +func (b B[T]) Bat() { + t := new(T) + if tt := reflect.TypeOf(t); tt.Kind() != reflect.Pointer || tt.Elem().Kind() != reflect.Int { + panic("unexpected type, want: *int, got: "+tt.String()) + } +} + +type Foo struct { + A[string] +} +func main() { + Foo{}.A.Bat() + Foo{}.A.B.Bat() + Foo{}.Bat() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48276a.go b/platform/dbops/binaries/go/go/test/typeparam/issue48276a.go new file mode 100644 index 0000000000000000000000000000000000000000..2a79268198d83aec5eb9472d73762d4209f9bdc5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48276a.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func main() { + IsZero[int](0) +} + +func IsZero[T comparable](val T) bool { + var zero T + fmt.Printf("%v:%v\n", zero, val) + return val != zero +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48276a.out b/platform/dbops/binaries/go/go/test/typeparam/issue48276a.out new file mode 100644 index 0000000000000000000000000000000000000000..8f38db999d80ee0bb857f17b7f5c5b3d527a299a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48276a.out @@ -0,0 +1 @@ +0:0 diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48276b.go b/platform/dbops/binaries/go/go/test/typeparam/issue48276b.go new file mode 100644 index 0000000000000000000000000000000000000000..774898d04060695b9d5408eea27130b871083d77 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48276b.go @@ -0,0 +1,15 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + f[interface{}](nil) +} + +func f[T any](x T) { + var _ interface{} = x +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48280.go b/platform/dbops/binaries/go/go/test/typeparam/issue48280.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48280.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48306.go b/platform/dbops/binaries/go/go/test/typeparam/issue48306.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48306.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48317.go b/platform/dbops/binaries/go/go/test/typeparam/issue48317.go new file mode 100644 index 0000000000000000000000000000000000000000..0220360ed8d6c9eb8b699fd42e14b1525a96d9dd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48317.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "encoding/json" +) + +type A[T any] struct { + F1 string `json:"t1"` + F2 T `json:"t2"` + B B `json:"t3"` +} + +type B struct { + F4 int `json:"t4"` +} + +func a[T any]() { + data := `{"t1":"1","t2":2,"t3":{"t4":4}}` + a1 := A[T]{} + if err := json.Unmarshal([]byte(data), &a1); err != nil { + panic(err) + } + if bytes, err := json.Marshal(&a1); err != nil { + panic(err) + } else if string(bytes) != data { + panic(string(bytes)) + } +} + +func main() { + a[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48318.go b/platform/dbops/binaries/go/go/test/typeparam/issue48318.go new file mode 100644 index 0000000000000000000000000000000000000000..b75c520c6e3240d5ff8080565ff7ce877397a7d8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48318.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "encoding/xml" + "fmt" +) + +type A[T, U any] struct { + Name T `xml:"name"` + Data U `xml:"data"` +} + +func main() { + src := &A[string, int]{Name: "name", Data: 1} + data, err := xml.Marshal(src) + if err != nil { + panic(err) + } + dst := &A[string, int]{} + err = xml.Unmarshal(data, dst) + if err != nil { + panic(err) + } + if *src != *dst { + panic(fmt.Sprintf("wanted %#v got %#v", src, dst)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48337a.go b/platform/dbops/binaries/go/go/test/typeparam/issue48337a.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48337a.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48337a.out b/platform/dbops/binaries/go/go/test/typeparam/issue48337a.out new file mode 100644 index 0000000000000000000000000000000000000000..fa8d3eedcbabae2cd05ed962050ce17cc5350425 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48337a.out @@ -0,0 +1 @@ +this file does import sync diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48337b.go b/platform/dbops/binaries/go/go/test/typeparam/issue48337b.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48337b.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48344.go b/platform/dbops/binaries/go/go/test/typeparam/issue48344.go new file mode 100644 index 0000000000000000000000000000000000000000..220bce948498ceb684bffe2620b63a549ba564e7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48344.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type G[T any] interface { + g() +} + +type Foo[T any] struct { +} + +func (foo *Foo[T]) g() { + +} + +func f[T any]() { + v := []G[T]{} + v = append(v, &Foo[T]{}) +} +func main() { + f[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48424.go b/platform/dbops/binaries/go/go/test/typeparam/issue48424.go new file mode 100644 index 0000000000000000000000000000000000000000..c5e5d4b105f31dd2a938c523424a6f57c2d8bda6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48424.go @@ -0,0 +1,54 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Smoke test for constraint literals with elided interface +// per issue #48424. + +package main + +func identity[T int](x T) T { + return x +} + +func min[T int | string](x, y T) T { + if x < y { + return x + } + return y +} + +func max[T ~int | ~float64](x, y T) T { + if x > y { + return x + } + return y +} + +func main() { + if identity(1) != 1 { + panic("identity(1) failed") + } + + if min(2, 3) != 2 { + panic("min(2, 3) failed") + } + + if min("foo", "bar") != "bar" { + panic(`min("foo", "bar") failed`) + } + + if max(2, 3) != 3 { + panic("max(2, 3) failed") + } +} + +// Some random type parameter lists with elided interfaces. + +type ( + _[T struct{}] struct{} + _[M map[K]V, K comparable, V any] struct{} + _[_ interface{} | int] struct{} +) diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48453.go b/platform/dbops/binaries/go/go/test/typeparam/issue48453.go new file mode 100644 index 0000000000000000000000000000000000000000..ef8c7f766fd47e56932c52e3c966e0361c79cf49 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48453.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +//go:noinline +func CopyMap[M interface{ ~map[K]V }, K comparable, V any](m M) M { + out := make(M, len(m)) + for k, v := range m { + out[k] = v + } + return out +} + +func main() { + var m map[*string]int + CopyMap(m) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48454.go b/platform/dbops/binaries/go/go/test/typeparam/issue48454.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48454.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48462.go b/platform/dbops/binaries/go/go/test/typeparam/issue48462.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48462.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48537.go b/platform/dbops/binaries/go/go/test/typeparam/issue48537.go new file mode 100644 index 0000000000000000000000000000000000000000..3ae85c794b0496ba948f192461a23afc960068d9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48537.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { +} + +type C interface { + map[int]string +} + +func f[A C]() A { + return A{ + 1: "a", + 2: "b", + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48538.go b/platform/dbops/binaries/go/go/test/typeparam/issue48538.go new file mode 100644 index 0000000000000000000000000000000000000000..985f84ebc8d73cb2a0bbdccc75d97a80d53ec5a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48538.go @@ -0,0 +1,60 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Testing composite literal for a type param constrained to be a struct or a map. + +package p + +type C interface { + ~struct{ b1, b2 string } +} + +func f[T C]() T { + return T{ + b1: "a", + b2: "b", + } +} + +func f2[T ~struct{ b1, b2 string }]() T { + return T{ + b1: "a", + b2: "b", + } +} + +type D interface { + map[string]string | S +} + +type S map[string]string + +func g[T D]() T { + b1 := "foo" + b2 := "bar" + return T{ + b1: "a", + b2: "b", + } +} + +func g2[T map[string]string]() T { + b1 := "foo" + b2 := "bar" + return T{ + b1: "a", + b2: "b", + } +} + +func g3[T S]() T { + b1 := "foo" + b2 := "bar" + return T{ + b1: "a", + b2: "b", + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48598.go b/platform/dbops/binaries/go/go/test/typeparam/issue48598.go new file mode 100644 index 0000000000000000000000000000000000000000..945b33269b65ed65621683b384c9a406f9e63538 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48598.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Iterator[T any] interface { + Iterate() +} + +type IteratorFunc[T any] func(fn func(T) bool) + +func (f IteratorFunc[T]) Iterate() { +} + +func FromIterator[T any](it Iterator[T]) { + it.Iterate() +} + +func Foo[T, R any]() { + FromIterator[R](IteratorFunc[R](nil)) +} + +func main() { + Foo[int, int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48602.go b/platform/dbops/binaries/go/go/test/typeparam/issue48602.go new file mode 100644 index 0000000000000000000000000000000000000000..c544697399d7f0c0a5a7c9aa0ba061aef385a98a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48602.go @@ -0,0 +1,25 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Iterator[T any] interface { + Iterate(fn T) +} + +type IteratorFunc[T any] func(fn T) + +func (f IteratorFunc[T]) Iterate(fn T) { + f(fn) +} + +func Foo[R any]() { + var _ Iterator[R] = IteratorFunc[R](nil) +} + +func main() { + Foo[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48604.go b/platform/dbops/binaries/go/go/test/typeparam/issue48604.go new file mode 100644 index 0000000000000000000000000000000000000000..348abf7c90005d65d0b85cf2187fbae031a29a67 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48604.go @@ -0,0 +1,25 @@ +// build + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Foo[T any] interface { + CreateBar() Bar[T] +} + +type Bar[T any] func() Bar[T] + +func (f Bar[T]) CreateBar() Bar[T] { + return f +} + +func abc[R any]() { + var _ Foo[R] = Bar[R](nil)() +} + +func main() { + abc[int]() +} \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48609.go b/platform/dbops/binaries/go/go/test/typeparam/issue48609.go new file mode 100644 index 0000000000000000000000000000000000000000..53144d206aad60010496a9422b94a53b0bf47846 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48609.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f[T ~chan E, E any](e E) T { + ch := make(T) + go func() { + defer close(ch) + ch <- e + }() + return ch +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48617.go b/platform/dbops/binaries/go/go/test/typeparam/issue48617.go new file mode 100644 index 0000000000000000000000000000000000000000..96978d4c9d80e96e8f849250a315c09af98e64c1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48617.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Foo[T any] interface { + CreateBar() Bar[T] +} + +type Bar[T any] func() Bar[T] + +func (f Bar[T]) CreateBar() Bar[T] { + return f +} + +func abc[T any]() { + var b Bar[T] = func() Bar[T] { + var b Bar[T] + return b + } + var _ Foo[T] = b() +} + +func main() { + abc[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48645a.go b/platform/dbops/binaries/go/go/test/typeparam/issue48645a.go new file mode 100644 index 0000000000000000000000000000000000000000..39267a9c2f68bd12a90f44cd553d2b0fccc4a230 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48645a.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "reflect" +) + +type Stream[T any] struct { +} + +func (s Stream[T]) DropWhile() Stream[T] { + return Pipe[T, T](s) +} + +func Pipe[T, R any](s Stream[T]) Stream[R] { + it := func(fn func(R) bool) { + } + fmt.Println(reflect.TypeOf(it).String()) + return Stream[R]{} +} + +func main() { + s := Stream[int]{} + s = s.DropWhile() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48645a.out b/platform/dbops/binaries/go/go/test/typeparam/issue48645a.out new file mode 100644 index 0000000000000000000000000000000000000000..5093d0f0ffce708e205e916a3737f7496502177b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48645a.out @@ -0,0 +1 @@ +func(func(int) bool) diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48645b.go b/platform/dbops/binaries/go/go/test/typeparam/issue48645b.go new file mode 100644 index 0000000000000000000000000000000000000000..619e7ee8b5b209f7c4907fef5a36b08841c159bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48645b.go @@ -0,0 +1,81 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Iterator[T any] interface { + Iterate(fn func(T) bool) +} + +type IteratorFunc[T any] func(fn func(T) bool) + +func (f IteratorFunc[T]) Iterate(fn func(T) bool) { + f(fn) +} + +type Stream[T any] struct { + it Iterator[T] +} + +func (s Stream[T]) Iterate(fn func(T) bool) { + if s.it == nil { + return + } + s.it.Iterate(fn) +} + +func FromIterator[T any](it Iterator[T]) Stream[T] { + return Stream[T]{it: it} +} + +func (s Stream[T]) DropWhile(fn func(T) bool) Stream[T] { + return Pipe[T, T](s, func(t T) (T, bool) { + return t, true + }) +} + +func Pipe[T, R any](s Stream[T], op func(d T) (R, bool)) Stream[R] { + it := func(fn func(R) bool) { + // XXX Not getting the closure right when converting to interface. + // s.it.Iterate(func(t T) bool { + // r, ok := op(t) + // if !ok { + // return true + // } + + // return fn(r) + // }) + } + + return FromIterator[R](IteratorFunc[R](it)) +} + +func Reduce[T, U any](s Stream[T], identity U, acc func(U, T) U) (r U) { + r = identity + s.Iterate(func(t T) bool { + r = acc(r, t) + return true + }) + + return r +} + +type myIterator struct { +} + +func (myIterator) Iterate(fn func(int) bool) { +} + +func main() { + s := Stream[int]{} + s.it = myIterator{} + s = s.DropWhile(func(i int) bool { + return false + }) + Reduce(s, nil, func(acc []int, e int) []int { + return append(acc, e) + }) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48711.go b/platform/dbops/binaries/go/go/test/typeparam/issue48711.go new file mode 100644 index 0000000000000000000000000000000000000000..477a5d597897f0eca278b5575074571b18c124bf --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48711.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T interface{ ~[]P }, P any](t T) { // ERROR "instantiation cycle" + if t == nil { + return + } + f[[]T, T]([]T{t}) +} + +func main() { + f[[]int](nil) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48716.go b/platform/dbops/binaries/go/go/test/typeparam/issue48716.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48716.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48838.go b/platform/dbops/binaries/go/go/test/typeparam/issue48838.go new file mode 100644 index 0000000000000000000000000000000000000000..1711d0405d3f10411c425d94ec6650ecee5d35bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48838.go @@ -0,0 +1,31 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + check[string]() +} + +func check[T any]() { + var result setter[T] + switch result.(type) { + case fooA[T]: + case fooB[T]: + } +} + +type setter[T any] interface { + Set(T) +} + +type fooA[T any] struct{} + +func (fooA[T]) Set(T) {} + +type fooB[T any] struct{} + +func (fooB[T]) Set(T) {} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue48962.go b/platform/dbops/binaries/go/go/test/typeparam/issue48962.go new file mode 100644 index 0000000000000000000000000000000000000000..24d0eb002a3e762db87328399ca516946f1265f6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue48962.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49027.go b/platform/dbops/binaries/go/go/test/typeparam/issue49027.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49027.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49049.go b/platform/dbops/binaries/go/go/test/typeparam/issue49049.go new file mode 100644 index 0000000000000000000000000000000000000000..b4b3bae59b4ccbcc840503a27e30bd3989295a48 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49049.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type A[T any] interface { + m() +} + +type Z struct { + a,b int +} + +func (z *Z) m() { +} + +func test[T any]() { + var a A[T] = &Z{} + f := a.m + f() +} +func main() { + test[string]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49241.go b/platform/dbops/binaries/go/go/test/typeparam/issue49241.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49241.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49246.go b/platform/dbops/binaries/go/go/test/typeparam/issue49246.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49246.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49295.go b/platform/dbops/binaries/go/go/test/typeparam/issue49295.go new file mode 100644 index 0000000000000000000000000000000000000000..f96c896eac0d472f82c03ba47682acbd339e6616 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49295.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "io" + +type Reader struct { + buf []byte +} +type Token *[16]byte + +func Read[T interface{ ~*[16]byte }](r *Reader) (t T, err error) { + if n := len(t); len(r.buf) >= n { + t = T(r.buf[:n]) + r.buf = r.buf[n:] + return + } + err = io.EOF + return +} + +func main() { + r := &Reader{buf: []byte("0123456789abcdef")} + token, err := Read[Token](r) + _, _ = token, err +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49309.go b/platform/dbops/binaries/go/go/test/typeparam/issue49309.go new file mode 100644 index 0000000000000000000000000000000000000000..16c97cd451a2156c66ddeb2f1bdfe060995a31a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49309.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func genfunc[T any](f func(c T)) { + var r T + + f(r) +} + +func myfunc(c string) { + test2(c) +} + +//go:noinline +func test2(a interface{}) { + _ = a.(string) +} + +func main() { + genfunc(myfunc) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49421.go b/platform/dbops/binaries/go/go/test/typeparam/issue49421.go new file mode 100644 index 0000000000000000000000000000000000000000..65c32afbf42044d5525c26d7ec59d3c6606f7f60 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49421.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + var a, b foo + bar(a, b) +} + +type foo int + +func (a foo) less(b foo) bool { + return a < b +} + +type lesser[T any] interface { + less(T) bool + comparable +} + +func bar[T lesser[T]](a, b T) { + a.less(b) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49432.go b/platform/dbops/binaries/go/go/test/typeparam/issue49432.go new file mode 100644 index 0000000000000000000000000000000000000000..d522b2281062daf663fb85164ba8342755a6e314 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49432.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Handler func(in ...interface{}) + +type Foo[T any] struct{} + +func (b *Foo[T]) Bar(in ...interface{}) {} + +func (b *Foo[T]) Init() { + _ = Handler(b.Bar) +} + +func main() { + c := &Foo[int]{} + c.Init() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49497.go b/platform/dbops/binaries/go/go/test/typeparam/issue49497.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49497.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49516.go b/platform/dbops/binaries/go/go/test/typeparam/issue49516.go new file mode 100644 index 0000000000000000000000000000000000000000..11b460df92a8ebc1ce8f14c5f3022de12c96257b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49516.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Q[T any] struct { + s []T +} + +func (q *Q[T]) Push(v ...T) { + q.s = append(q.s, v...) +} + +func pushN(push func(*Q[int], ...int), n int) { + var q Q[int] + for i := 0; i < n; i++ { + push(&q, i) + } +} + +func f() { + pushN((*Q[int]).Push, 100) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49524.go b/platform/dbops/binaries/go/go/test/typeparam/issue49524.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49524.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49536.go b/platform/dbops/binaries/go/go/test/typeparam/issue49536.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49536.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49538.go b/platform/dbops/binaries/go/go/test/typeparam/issue49538.go new file mode 100644 index 0000000000000000000000000000000000000000..cb22a06e2d203ca7b5c7eaef896a8c35521fa41c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49538.go @@ -0,0 +1,23 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type I interface { + M(interface{}) +} + +type a[T any] struct{} + +func (a[T]) M(interface{}) {} + +func f[T I](t *T) { + (*t).M(t) +} + +func g() { + f(&a[int]{}) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49547.go b/platform/dbops/binaries/go/go/test/typeparam/issue49547.go new file mode 100644 index 0000000000000000000000000000000000000000..6d359baa3132aea156b0055b119fcb388106c995 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49547.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type foo int + +func main() { + want := "main.F[main.foo]" + got := fmt.Sprintf("%T", F[foo]{}) + if got != want { + fmt.Printf("want: %s, got: %s\n", want, got) + } +} + +type F[T any] struct { +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49611.go b/platform/dbops/binaries/go/go/test/typeparam/issue49611.go new file mode 100644 index 0000000000000000000000000000000000000000..879e4d2e900b75b21afe1728b9a96938b2026093 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49611.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f[T any]() { + var () +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49659.go b/platform/dbops/binaries/go/go/test/typeparam/issue49659.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49659.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49659b.go b/platform/dbops/binaries/go/go/test/typeparam/issue49659b.go new file mode 100644 index 0000000000000000000000000000000000000000..7e1535e0454a8dc6b46c048d7ff030a1c5ce3eae --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49659b.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Testing that AddrTaken logic doesn't cause problems for function instantiations + +package main + +type A[T interface{ []int | [5]int }] struct { + val T +} + +//go:noinline +func (a A[T]) F() { + _ = &a.val[2] +} + +func main() { + var x A[[]int] + x.val = make([]int, 4) + _ = &x.val[3] + x.F() + var y A[[5]int] + _ = &y.val[3] + y.F() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49667.go b/platform/dbops/binaries/go/go/test/typeparam/issue49667.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49667.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49875.go b/platform/dbops/binaries/go/go/test/typeparam/issue49875.go new file mode 100644 index 0000000000000000000000000000000000000000..3fbe48c8a0904ccb2cb6a70ea594805c50d641ee --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49875.go @@ -0,0 +1,14 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func f(args ...interface{}) {} + +func g() { + var args []any + f(args...) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue49893.go b/platform/dbops/binaries/go/go/test/typeparam/issue49893.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue49893.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50002.go b/platform/dbops/binaries/go/go/test/typeparam/issue50002.go new file mode 100644 index 0000000000000000000000000000000000000000..42d97f5482782616d651108307f452f21c793bca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50002.go @@ -0,0 +1,64 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test for cases where certain instantiations of a generic function (F in this +// example) will always fail on a type assertion or mismatch on a type case. + +package main + +import "fmt" + +type S struct{} + +func (S) M() byte { + return 0 +} + +type I[T any] interface { + M() T +} + +func F[T, A any](x I[T], shouldMatch bool) { + switch x.(type) { + case A: + if !shouldMatch { + fmt.Printf("wanted mis-match, got match") + } + default: + if shouldMatch { + fmt.Printf("wanted match, got mismatch") + } + } + + _, ok := x.(A) + if ok != shouldMatch { + fmt.Printf("ok: got %v, wanted %v", ok, shouldMatch) + } + + if !shouldMatch { + defer func() { + if shouldMatch { + fmt.Printf("Shouldn't have panicked") + } + recover() + }() + } + _ = x.(A) + if !shouldMatch { + fmt.Printf("Should have panicked") + } +} + +func main() { + // Test instantiation where the type switch/type asserts can't possibly succeed + // (since string does not implement I[byte]). + F[byte, string](S{}, false) + + // Test instantiation where the type switch/type asserts should succeed + // (since S does implement I[byte]) + F[byte, S](S{}, true) + F[byte, S](I[byte](S{}), true) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50109.go b/platform/dbops/binaries/go/go/test/typeparam/issue50109.go new file mode 100644 index 0000000000000000000000000000000000000000..30aebb2c948bea6174b5519c6e2f5fa61512f5d0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50109.go @@ -0,0 +1,105 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type AnyCacher[T any] interface { + // Get an item from the cache. Returns the item or nil, and a bool indicating + // whether the key was found. + Get(k string) (T, bool) + // Add an item to the cache, replacing any existing item. + Set(k string, x T) +} + +// Item ... +type Item[T any] struct { + Object T +} + +// AnyCache implements AnyCacher +type AnyCache[T any] struct { + *anyCache[T] +} + +type anyCache[T any] struct { + items map[string]Item[T] + janitor *janitor[T] // Needed for the failure in the issue +} + +// Set adds an item to the cache, replacing any existing item. +func (c *anyCache[T]) Set(k string, x T) { + c.items[k] = Item[T]{ + Object: x, + } +} + +// Get gets an item from the cache. Returns the item or nil, and a bool indicating +// whether the key was found. +func (c *anyCache[T]) Get(k string) (T, bool) { + // "Inlining" of get and Expired + item, found := c.items[k] + if !found { + var ret T + return ret, false + } + + return item.Object, true +} + +type janitor[T any] struct { + stop chan bool +} + +func newAnyCache[T any](m map[string]Item[T]) *anyCache[T] { + c := &anyCache[T]{ + items: m, + } + return c +} + +// NewAny[T any](...) returns a new AnyCache[T]. +func NewAny[T any]() *AnyCache[T] { + items := make(map[string]Item[T]) + return &AnyCache[T]{newAnyCache(items)} +} + +// NewAnyCacher[T any](...) returns an AnyCacher[T] interface. +func NewAnyCacher[T any]() AnyCacher[T] { + return NewAny[T]() +} + +type MyStruct struct { + Name string +} + +func main() { + // Create a generic cache. + // All items are cached as interface{} so they need to be cast back to their + // original type when retrieved. + // Failure in issue doesn't happen with 'any' replaced by 'interface{}' + c := NewAnyCacher[any]() + + myStruct := &MyStruct{"MySuperStruct"} + + c.Set("MySuperStruct", myStruct) + + myRawCachedStruct, found := c.Get("MySuperStruct") + + if found { + // Casting the retrieved object back to its original type + myCachedStruct := myRawCachedStruct.(*MyStruct) + fmt.Printf("%s", myCachedStruct.Name) + } else { + fmt.Printf("Error: MySuperStruct not found in cache") + } + + // Output: + // MySuperStruct +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50109.out b/platform/dbops/binaries/go/go/test/typeparam/issue50109.out new file mode 100644 index 0000000000000000000000000000000000000000..7d6ecc0c6d2bf0c54deda95d5c7652cce6ff4b40 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50109.out @@ -0,0 +1 @@ +MySuperStruct \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50109b.go b/platform/dbops/binaries/go/go/test/typeparam/issue50109b.go new file mode 100644 index 0000000000000000000000000000000000000000..ee494415ff60d440b47441220da12e53b5f6173d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50109b.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + F[any]() +} + +func F[T any]() I[T] { + return (*S1[T])(nil) +} + +type I[T any] interface{} + +type S1[T any] struct { + *S2[T] +} + +type S2[T any] struct { + S3 *S3[T] +} + +type S3[T any] struct { + x int +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50121.go b/platform/dbops/binaries/go/go/test/typeparam/issue50121.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50121.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50121b.go b/platform/dbops/binaries/go/go/test/typeparam/issue50121b.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50121b.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50147.go b/platform/dbops/binaries/go/go/test/typeparam/issue50147.go new file mode 100644 index 0000000000000000000000000000000000000000..f97bace894b8ad715c366e5f7b2674e4c97706af --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50147.go @@ -0,0 +1,11 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func Foo[T any, U interface{ *T }](x T) { + var _ U = &x +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50177.go b/platform/dbops/binaries/go/go/test/typeparam/issue50177.go new file mode 100644 index 0000000000000000000000000000000000000000..c4858fc6dd1ac6c5a88d47b177082f3ac5561dd1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50177.go @@ -0,0 +1,101 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type Fn[T any] func(T) +type FnErr[T any] func(T) error + +// Test that local generic types across functions don't conflict, and they also don't +// conflict with local non-generic types and local variables. +func caller0() { + type X[T any] struct { + fn Fn[int] + } + + x := X[int]{func(v int) { fmt.Println(v) }} + x.fn(0) +} + +func caller1(val int) { + type X[T any] struct { + fn FnErr[int] + } + + x := X[int]{func(v int) error { fmt.Println(v); return nil }} + x.fn(0) +} + +func caller1a(val int) { + type X struct { + fn func(float64) error + } + + x := X{func(v float64) error { fmt.Println(v); return nil }} + x.fn(float64(3.2)) +} + +func caller1b(val int) { + type Y struct { + fn func(float64) error + } + + X := Y{func(v float64) error { fmt.Println(v); return nil }} + X.fn(float64(3.2)) +} + +// Test that local generic types within different if clauses don't conflict. +func caller2(val int) { + if val > 2 { + type X[T any] struct { + fn func(v int) float64 + } + + x := X[int]{func(v int) float64 { fmt.Println(v); return 1.5 }} + x.fn(0) + } else { + type X[T any] struct { + fn func(v int) int + } + x := X[int]{func(v int) int { fmt.Println(v); return 5 }} + x.fn(0) + } +} + +// Test that local generic types within different cases don't conflict with each +// other or with local non-generic types or local variables. +func caller3(val int) { + switch val { + case 0: + type X[T any] struct { + fn func(v int) float64 + } + + x := X[int]{func(v int) float64 { fmt.Println(v); return 1.5 }} + x.fn(0) + case 1: + type X[T any] struct { + fn func(v int) int + } + x := X[int]{func(v int) int { fmt.Println(v); return 5 }} + x.fn(0) + case 2: + type X struct { + fn func(v int) bool + } + x := X{func(v int) bool { fmt.Println(v); return false }} + x.fn(0) + case 3: + type Y struct { + fn func(v int) bool + } + X := Y{func(v int) bool { fmt.Println(v); return false }} + X.fn(0) + + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50193.go b/platform/dbops/binaries/go/go/test/typeparam/issue50193.go new file mode 100644 index 0000000000000000000000000000000000000000..8b4b84180f6e2f9dbe0210877a0648a463c149cc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50193.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Complex interface { + ~complex64 | ~complex128 +} + +func zero[T Complex]() T { + return T(0) +} +func pi[T Complex]() T { + return T(3.14) +} +func sqrtN1[T Complex]() T { + return T(-1i) +} + +func main() { + fmt.Println(zero[complex128]()) + fmt.Println(pi[complex128]()) + fmt.Println(sqrtN1[complex128]()) + fmt.Println(zero[complex64]()) + fmt.Println(pi[complex64]()) + fmt.Println(sqrtN1[complex64]()) +} + diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50193.out b/platform/dbops/binaries/go/go/test/typeparam/issue50193.out new file mode 100644 index 0000000000000000000000000000000000000000..68186222c7fb9da4912c0528c518c4a800130fd2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50193.out @@ -0,0 +1,6 @@ +(0+0i) +(3.14+0i) +(0-1i) +(0+0i) +(3.14+0i) +(0-1i) diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50259.go b/platform/dbops/binaries/go/go/test/typeparam/issue50259.go new file mode 100644 index 0000000000000000000000000000000000000000..50edf8f737527a274d3168bd5214d95c5a7b36c0 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50259.go @@ -0,0 +1,13 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var x T[B] + +type T[_ any] struct{} +type A T[B] +type B = T[A] diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50264.go b/platform/dbops/binaries/go/go/test/typeparam/issue50264.go new file mode 100644 index 0000000000000000000000000000000000000000..1acab87f42a2c714a52708471aaf21eb789f71f2 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50264.go @@ -0,0 +1,45 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type hello struct{} + +func main() { + _ = Some(hello{}) + res := Applicative2(func(a int, b int) int { + return 0 + }) + _ = res +} + +type NoneType[T any] struct{} + +func (r NoneType[T]) Recover() any { + return nil +} + +type Func2[A1, A2, R any] func(a1 A1, a2 A2) R + +func Some[T any](v T) any { + _ = Some2[T](v) + return NoneType[T]{}.Recover() +} + +//go:noinline +func Some2[T any](v T) any { + return v +} + +type Nil struct{} + +type ApplicativeFunctor2[H, HT, A1, A2, R any] struct { + h any +} + +func Applicative2[A1, A2, R any](fn Func2[A1, A2, R]) ApplicativeFunctor2[Nil, Nil, A1, A2, R] { + return ApplicativeFunctor2[Nil, Nil, A1, A2, R]{Some(Nil{})} +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50317.go b/platform/dbops/binaries/go/go/test/typeparam/issue50317.go new file mode 100644 index 0000000000000000000000000000000000000000..c33c4f061c7d45c6c1954a84e5d08f9ea8b0b14d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50317.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type S struct{} + +func (S) _[_ any]() {} // ERROR "method must have no type parameters" + +type _ interface { + m[_ any]() // ERROR "method must have no type parameters" +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50417.go b/platform/dbops/binaries/go/go/test/typeparam/issue50417.go new file mode 100644 index 0000000000000000000000000000000000000000..b32e270bdfca8c5ca6e5ca075e24f37cc2445b51 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50417.go @@ -0,0 +1,146 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() {} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + +/* +type Sf struct { + f int +} + +func f0[P Sf](p P) { + _ = p.f + p.f = 0 +} + +func f0t[P ~struct{ f int }](p P) { + _ = p.f + p.f = 0 +} + +var _ = f0[Sf] +var _ = f0t[Sf] + +func f1[P interface { + ~struct{ f int } + m() +}](p P) { + _ = p.f + p.f = 0 + p.m() +} + +var _ = f1[Sfm] + +type Sm struct{} + +func (Sm) m() {} + +type Sfm struct { + f int +} + +func (Sfm) m() {} + +func f2[P interface { + Sfm + m() +}](p P) { + _ = p.f + p.f = 0 + p.m() +} + +var _ = f2[Sfm] + +// special case: core type is a named pointer type + +type PSfm *Sfm + +func f3[P interface{ PSfm }](p P) { + _ = p.f + p.f = 0 +} + +var _ = f3[PSfm] + +// special case: core type is an unnamed pointer type + +func f4[P interface{ *Sfm }](p P) { + _ = p.f + p.f = 0 +} + +var _ = f4[*Sfm] + +type A int +type B int +type C float64 + +type Int interface { + *Sf | A + *Sf | B +} + +func f5[P Int](p P) { + _ = p.f + p.f = 0 +} + +var _ = f5[*Sf] + +type Int2 interface { + *Sf | A + any + *Sf | C +} + +func f6[P Int2](p P) { + _ = p.f + p.f = 0 +} + +var _ = f6[*Sf] + +type Int3 interface { + Sf + ~struct{ f int } +} + +func f7[P Int3](p P) { + _ = p.f + p.f = 0 +} + +var _ = f7[Sf] + +type Em1 interface { + *Sf | A +} + +type Em2 interface { + *Sf | B +} + +type Int4 interface { + Em1 + Em2 + any +} + +func f8[P Int4](p P) { + _ = p.f + p.f = 0 +} + +var _ = f8[*Sf] +*/ diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50417b.go b/platform/dbops/binaries/go/go/test/typeparam/issue50417b.go new file mode 100644 index 0000000000000000000000000000000000000000..1c803b09bdff0987164d8fe5f4e2e8278bbba66f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50417b.go @@ -0,0 +1,58 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() {} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. + +/* +import "fmt" + +type MyStruct struct { + b1, b2 string + E +} + +type E struct { + val int +} + +type C interface { + ~struct { + b1, b2 string + E + } +} + +func f[T C]() T { + var x T = T{ + b1: "a", + b2: "b", + } + + if got, want := x.b2, "b"; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + x.b1 = "y" + x.val = 5 + + return x +} + +func main() { + x := f[MyStruct]() + if got, want := x.b1, "y"; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + if got, want := x.val, 5; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} +*/ diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50419.go b/platform/dbops/binaries/go/go/test/typeparam/issue50419.go new file mode 100644 index 0000000000000000000000000000000000000000..dfe55f9445991374f1aad65c483f43b46c14b060 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50419.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that type substitution works correctly even for a method of a generic type +// that has multiple blank type params. + +package main + +import ( + "fmt" +) + +func main() { + foo := &Foo[string, int]{ + valueA: "i am a string", + valueB: 123, + } + if got, want := fmt.Sprintln(foo), "i am a string 123\n"; got != want { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } +} + +type Foo[T1 any, T2 any] struct { + valueA T1 + valueB T2 +} + +func (f *Foo[_, _]) String() string { + return fmt.Sprintf("%v %v", f.valueA, f.valueB) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50437.go b/platform/dbops/binaries/go/go/test/typeparam/issue50437.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50437.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50481b.go b/platform/dbops/binaries/go/go/test/typeparam/issue50481b.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50481b.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50481c.go b/platform/dbops/binaries/go/go/test/typeparam/issue50481c.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50481c.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50481c.out b/platform/dbops/binaries/go/go/test/typeparam/issue50481c.out new file mode 100644 index 0000000000000000000000000000000000000000..573541ac9702dd3969c9bc859d2b91ec1f7e6e56 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50481c.out @@ -0,0 +1 @@ +0 diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50485.go b/platform/dbops/binaries/go/go/test/typeparam/issue50485.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50485.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50486.go b/platform/dbops/binaries/go/go/test/typeparam/issue50486.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50486.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50552.go b/platform/dbops/binaries/go/go/test/typeparam/issue50552.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50552.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50561.go b/platform/dbops/binaries/go/go/test/typeparam/issue50561.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50561.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50598.go b/platform/dbops/binaries/go/go/test/typeparam/issue50598.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50598.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50642.go b/platform/dbops/binaries/go/go/test/typeparam/issue50642.go new file mode 100644 index 0000000000000000000000000000000000000000..d2d4a6690750d2f0b762b27860ea2519139af254 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50642.go @@ -0,0 +1,63 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type Temp[T any] struct { +} + +var temp, temp1 any +var ch any + +func (it Temp[T]) HasNext() bool { + var ok bool + temp1 = <-ch.(chan T) + // test conversion of T to interface{} during an OAS2RECV + temp, ok = <-ch.(chan T) + return ok +} + +type MyInt int + +func (i MyInt) String() string { + return "a" +} + +type Stringer interface { + String() string +} + +type Temp2[T Stringer] struct { +} + +var temp2 Stringer + +func (it Temp2[T]) HasNext() string { + var x map[int]T + + var ok bool + // test conversion of T to Stringer during an OAS2MAPR + temp2, ok = x[43] + _ = ok + return temp2.String() +} + +func main() { + ch1 := make(chan int, 2) + ch1 <- 5 + ch1 <- 6 + ch = ch1 + iter := Temp[int]{} + iter.HasNext() + + iter2 := Temp2[MyInt]{} + if got, want := iter2.HasNext(), "a"; got != want { + panic(fmt.Sprintf("got %v, want %v", got, want)) + } + +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690a.go b/platform/dbops/binaries/go/go/test/typeparam/issue50690a.go new file mode 100644 index 0000000000000000000000000000000000000000..6691af0a07303657c12f0dc6ad6d227c2542d261 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690a.go @@ -0,0 +1,75 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +// Numeric expresses a type constraint satisfied by any numeric type. +type Numeric interface { + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~float32 | ~float64 | + ~complex64 | ~complex128 +} + +// Sum returns the sum of the provided arguments. +func Sum[T Numeric](args ...T) T { + var sum T + for i := 0; i < len(args); i++ { + sum += args[i] + } + return sum +} + +// Ledger is an identifiable, financial record. +type Ledger[T ~string, K Numeric] struct { + // ID identifies the ledger. + ID_ T + + // Amounts is a list of monies associated with this ledger. + Amounts_ []K + + // SumFn is a function that can be used to sum the amounts + // in this ledger. + SumFn_ func(...K) K +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor methods instead. + +func (l Ledger[T, _]) ID() T { return l.ID_ } +func (l Ledger[_, K]) Amounts() []K { return l.Amounts_ } +func (l Ledger[_, K]) SumFn() func(...K) K { return l.SumFn_ } + +func PrintLedger[ + T ~string, + K Numeric, + L interface { + ~struct { + ID_ T + Amounts_ []K + SumFn_ func(...K) K + } + ID() T + Amounts() []K + SumFn() func(...K) K + }, +](l L) { + fmt.Printf("%s has a sum of %v\n", l.ID(), l.SumFn()(l.Amounts()...)) +} + +func main() { + PrintLedger(Ledger[string, int]{ + ID_: "fake", + Amounts_: []int{1, 2, 3}, + SumFn_: Sum[int], + }) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690a.out b/platform/dbops/binaries/go/go/test/typeparam/issue50690a.out new file mode 100644 index 0000000000000000000000000000000000000000..293276716f62d2da174ba98027bf0c7b97dcdeca --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690a.out @@ -0,0 +1 @@ +fake has a sum of 6 diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690b.go b/platform/dbops/binaries/go/go/test/typeparam/issue50690b.go new file mode 100644 index 0000000000000000000000000000000000000000..09c84e089dfdb7027fc58e4f650e6f72c99acbd4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690b.go @@ -0,0 +1,51 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Printer[T ~string] struct { + PrintFn func(T) +} + +func Print[T ~string](s T) { + fmt.Println(s) +} + +func PrintWithPrinter[T ~string, S interface { + ~struct { + ID T + PrintFn_ func(T) + } + PrintFn() func(T) +}](message T, obj S) { + obj.PrintFn()(message) +} + +type PrintShop[T ~string] struct { + ID T + PrintFn_ func(T) +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (s PrintShop[T]) PrintFn() func(T) { return s.PrintFn_ } + +func main() { + PrintWithPrinter( + "Hello, world.", + PrintShop[string]{ + ID: "fake", + PrintFn_: Print[string], + }, + ) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690b.out b/platform/dbops/binaries/go/go/test/typeparam/issue50690b.out new file mode 100644 index 0000000000000000000000000000000000000000..f75ba05f340c51065cbea2e1fdbfe5fe13144c97 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690b.out @@ -0,0 +1 @@ +Hello, world. diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690c.go b/platform/dbops/binaries/go/go/test/typeparam/issue50690c.go new file mode 100644 index 0000000000000000000000000000000000000000..2db1487ecb188a95d554f8d6fb9c1959b9de424e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690c.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Printer[T ~string] struct { + PrintFn func(T) +} + +func Print[T ~string](s T) { + fmt.Println(s) +} + +func PrintWithPrinter[T ~string, S interface { + ~struct { + ID T + PrintFn_ func(T) + } + PrintFn() func(T) +}](message T, obj S) { + obj.PrintFn()(message) +} + +func main() { + PrintWithPrinter( + "Hello, world.", + StructWithPrinter{ID: "fake", PrintFn_: Print[string]}, + ) +} + +type StructWithPrinter struct { + ID string + PrintFn_ func(string) +} + +// Field accesses through type parameters are disabled +// until we have a more thorough understanding of the +// implications on the spec. See issue #51576. +// Use accessor method instead. + +func (s StructWithPrinter) PrintFn() func(string) { + return s.PrintFn_ +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50690c.out b/platform/dbops/binaries/go/go/test/typeparam/issue50690c.out new file mode 100644 index 0000000000000000000000000000000000000000..f75ba05f340c51065cbea2e1fdbfe5fe13144c97 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50690c.out @@ -0,0 +1 @@ +Hello, world. diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50833.go b/platform/dbops/binaries/go/go/test/typeparam/issue50833.go new file mode 100644 index 0000000000000000000000000000000000000000..fe729b1f289f35b18a9b442db121a6fe892bb38a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50833.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type ( + S struct{ f int } + PS *S +) + +func a() []*S { return []*S{{f: 1}} } +func b() []PS { return []PS{{f: 1}} } + +func c[P *S]() []P { return []P{{f: 1}} } +func d[P PS]() []P { return []P{{f: 1}} } + +func main() { + c[*S]() + d[PS]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50841.go b/platform/dbops/binaries/go/go/test/typeparam/issue50841.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50841.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue50993.go b/platform/dbops/binaries/go/go/test/typeparam/issue50993.go new file mode 100644 index 0000000000000000000000000000000000000000..4d459fd04c1634ad97eac70daa20cb9633b4fe08 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue50993.go @@ -0,0 +1,35 @@ +// compile -d=checkptr + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "sync/atomic" + "unsafe" +) + +type Node[T any] struct { + Next *Node[T] + // Prev *Node[T] +} + +func LoadPointer[T any](addr **T) (val *T) { + return (*T)( + atomic.LoadPointer( + (*unsafe.Pointer)(unsafe.Pointer(addr)), + )) +} + +func (q *Node[T]) Pop() { + var tail, head *Node[T] + if head == LoadPointer(&tail) { + } +} + +func main() { + ch := Node[uint64]{} + ch.Pop() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51219.go b/platform/dbops/binaries/go/go/test/typeparam/issue51219.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51219.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51219.out b/platform/dbops/binaries/go/go/test/typeparam/issue51219.out new file mode 100644 index 0000000000000000000000000000000000000000..0967ef424bce6791893e9a57bb952f80fd536e93 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51219.out @@ -0,0 +1 @@ +{} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51219b.go b/platform/dbops/binaries/go/go/test/typeparam/issue51219b.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51219b.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51232.go b/platform/dbops/binaries/go/go/test/typeparam/issue51232.go new file mode 100644 index 0000000000000000000000000000000000000000..f4728f6e7cd310776a5adee13dda99a40e654a15 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51232.go @@ -0,0 +1,31 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type RC[RG any] interface { + ~[]RG +} + +type Fn[RCT RC[RG], RG any] func(RCT) + +type F[RCT RC[RG], RG any] interface { + Fn() Fn[RCT] // ERROR "not enough type arguments for type Fn: have 1, want 2" +} + +type concreteF[RCT RC[RG], RG any] struct { + makeFn func() Fn[RCT] // ERROR "not enough type arguments for type Fn: have 1, want 2" +} + +func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { // ERROR "not enough type arguments for type Fn: have 1, want 2" + return c.makeFn() +} + +func NewConcrete[RCT RC[RG], RG any](Rc RCT) F[RCT] { // ERROR "not enough type arguments for type F: have 1, want 2" + return &concreteF[RCT]{ // ERROR "cannot use" "not enough type arguments for type concreteF: have 1, want 2" + makeFn: nil, + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51233.go b/platform/dbops/binaries/go/go/test/typeparam/issue51233.go new file mode 100644 index 0000000000000000000000000000000000000000..5f2a045d84735704d8c63d5bab88337424ded6f9 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51233.go @@ -0,0 +1,28 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +package p + +// As of issue #51527, type-type inference has been disabled. + +type RC[RG any] interface { + ~[]RG +} + +type Fn[RCT RC[RG], RG any] func(RCT) + +type FFn[RCT RC[RG], RG any] func() Fn[RCT] // ERROR "not enough type arguments for type Fn: have 1, want 2" + +type F[RCT RC[RG], RG any] interface { + Fn() Fn[RCT] // ERROR "not enough type arguments for type Fn: have 1, want 2" +} + +type concreteF[RCT RC[RG], RG any] struct { + makeFn FFn[RCT] // ERROR "not enough type arguments for type FFn: have 1, want 2" +} + +func (c *concreteF[RCT, RG]) Fn() Fn[RCT] { // ERROR "not enough type arguments for type Fn: have 1, want 2" + return c.makeFn() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51236.go b/platform/dbops/binaries/go/go/test/typeparam/issue51236.go new file mode 100644 index 0000000000000000000000000000000000000000..51fde1e9b6819fbc585edf9e19c984031a5e63ae --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51236.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + []byte +} + +func F[T I]() { + var t T + explodes(t) +} + +func explodes(b []byte) {} + +func main() { + +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51245.go b/platform/dbops/binaries/go/go/test/typeparam/issue51245.go new file mode 100644 index 0000000000000000000000000000000000000000..425d51713ff4d1fe629457a0982354b1f053392f --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51245.go @@ -0,0 +1,16 @@ +// build + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T[P any] int +const C T[int] = 3 + +type T2 int +const C2 T2 = 9 + +func main() { +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51250a.go b/platform/dbops/binaries/go/go/test/typeparam/issue51250a.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51250a.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51303.go b/platform/dbops/binaries/go/go/test/typeparam/issue51303.go new file mode 100644 index 0000000000000000000000000000000000000000..a3a784969b391fedfa2dbea2e1007dba7348dca6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51303.go @@ -0,0 +1,65 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +func main() { + x := [][]int{{1}} + y := [][]int{{2, 3}} + IntersectSS(x, y) +} + +type list[E any] interface { + ~[]E + Equal(x, y E) bool +} + +// ss is a set of sets +type ss[E comparable, T []E] []T + +func (ss[E, T]) Equal(a, b T) bool { + return SetEq(a, b) +} + +func IntersectSS[E comparable](x, y [][]E) [][]E { + return IntersectT[[]E, ss[E, []E]](ss[E, []E](x), ss[E, []E](y)) +} + +func IntersectT[E any, L list[E]](x, y L) L { + var z L +outer: + for _, xe := range x { + fmt.Println("xe", xe) + for _, ye := range y { + fmt.Println("ye", ye) + fmt.Println("x", x) + if x.Equal(xe, ye) { + fmt.Println("appending") + z = append(z, xe) + continue outer + } + } + } + return z +} + +func SetEq[S []E, E comparable](x, y S) bool { + fmt.Println("SetEq", x, y) +outer: + for _, xe := range x { + for _, ye := range y { + if xe == ye { + continue outer + } + } + return false // xs wasn't found in y + } + return true +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51303.out b/platform/dbops/binaries/go/go/test/typeparam/issue51303.out new file mode 100644 index 0000000000000000000000000000000000000000..34b3be32ddd64cc5cf2aa06caedaccc254c544dc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51303.out @@ -0,0 +1,4 @@ +xe [1] +ye [2 3] +x [[1]] +SetEq [1] [2 3] diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51355.go b/platform/dbops/binaries/go/go/test/typeparam/issue51355.go new file mode 100644 index 0000000000000000000000000000000000000000..321d5ff96e4496e467855857f849d84b0c80f697 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51355.go @@ -0,0 +1,31 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Cache[E comparable] struct { + adder func(...E) +} + +func New[E comparable]() *Cache[E] { + c := &Cache[E]{} + + c.adder = func(elements ...E) { + for _, value := range elements { + value := value + go func() { + println(value) + }() + } + } + + return c +} + +func main() { + c := New[string]() + c.adder("test") +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51367.go b/platform/dbops/binaries/go/go/test/typeparam/issue51367.go new file mode 100644 index 0000000000000000000000000000000000000000..aefbe673109b6c7187837e3464eef47858d0eb00 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51367.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51423.go b/platform/dbops/binaries/go/go/test/typeparam/issue51423.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51423.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51521.go b/platform/dbops/binaries/go/go/test/typeparam/issue51521.go new file mode 100644 index 0000000000000000000000000000000000000000..5eb4e35c185b0d420b13485e33c3d91f77c0f0eb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51521.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "strings" +) + +type I interface{ M() } + +func F[P I](p P) { defer catch(); p.M() } +func G[T any]() { defer catch(); interface{ M() T }.M(nil) } + +func main() { + F[I](nil) + G[int]() +} + +func catch() { + err := recover() + if err, ok := err.(error); ok && strings.Contains(err.Error(), "nil pointer dereference") { + return + } + fmt.Println("FAIL", err) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51522a.go b/platform/dbops/binaries/go/go/test/typeparam/issue51522a.go new file mode 100644 index 0000000000000000000000000000000000000000..3f854080a746d86dc39ec9f2fb93c7ab17ac67cc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51522a.go @@ -0,0 +1,42 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +package main + + +func f[T comparable](i any) { + var t T + + if i != t { + println("FAIL: if i != t") + } +} + +type myint int + +func (m myint) foo() { +} + +type fooer interface { + foo() +} + +type comparableFoo interface { + comparable + foo() +} + +func g[T comparableFoo](i fooer) { + var t T + + if i != t { + println("FAIL: if i != t") + } +} + +func main() { + f[int](int(0)) + g[myint](myint(0)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51522b.go b/platform/dbops/binaries/go/go/test/typeparam/issue51522b.go new file mode 100644 index 0000000000000000000000000000000000000000..115b6b9c425f2baea5a6461c949514171b55636d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51522b.go @@ -0,0 +1,62 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T comparable](i any) { + var t T + + switch i { + case t: + // ok + default: + println("FAIL: switch i") + } + + switch t { + case i: + // ok + default: + println("FAIL: switch t") + } +} + +type myint int + +func (m myint) foo() { +} + +type fooer interface { + foo() +} + +type comparableFoo interface { + comparable + foo() +} + +func g[T comparableFoo](i fooer) { + var t T + + switch i { + case t: + // ok + default: + println("FAIL: switch i") + } + + switch t { + case i: + // ok + default: + println("FAIL: switch t") + } +} + +func main() { + f[int](0) + g[myint](myint(0)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51700.go b/platform/dbops/binaries/go/go/test/typeparam/issue51700.go new file mode 100644 index 0000000000000000000000000000000000000000..bf8a1f6289bb5a46cc7172071db82460e1b30461 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51700.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[B any](b B) { + if b1, ok := any(b).(interface{ m1() }); ok { + panic(1) + _ = b1.(B) + } + if b2, ok := any(b).(interface{ m2() }); ok { + panic(2) + _ = b2.(B) + } +} + +type S struct{} + +func (S) m3() {} + +func main() { + f(S{}) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51765.go b/platform/dbops/binaries/go/go/test/typeparam/issue51765.go new file mode 100644 index 0000000000000000000000000000000000000000..683cb0f2e2c86a30bdfcce54da12d228ea829532 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51765.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type empty[T any] struct{} + +func (this *empty[T]) Next() (empty T, _ error) { + return empty, nil +} + +var _ = &empty[string]{} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51832.go b/platform/dbops/binaries/go/go/test/typeparam/issue51832.go new file mode 100644 index 0000000000000000000000000000000000000000..c325ae6c2e855d9a954f6bb5a0656fc97023838e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51832.go @@ -0,0 +1,25 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type F func() F + +func do[T any]() F { + return nil +} + +type G[T any] func() G[T] + +//go:noinline +func dog[T any]() G[T] { + return nil +} + +func main() { + do[int]() + dog[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51836.go b/platform/dbops/binaries/go/go/test/typeparam/issue51836.go new file mode 100644 index 0000000000000000000000000000000000000000..c755e74b9cdd1ad6689c008155ba77ecaf01f63d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51836.go @@ -0,0 +1,7 @@ +// compiledir -s + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51840.go b/platform/dbops/binaries/go/go/test/typeparam/issue51840.go new file mode 100644 index 0000000000000000000000000000000000000000..19fa3e468b26b1cee5686db3599c9be1886ac594 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51840.go @@ -0,0 +1,36 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Addr struct { + hi uint64 + lo uint64 + z *byte +} + +func EqualMap[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool { + for k, v1 := range m1 { + if v2, ok := m2[k]; !ok || v1 != v2 { + return false + } + } + return true +} + +type Set[T comparable] map[T]struct{} + +func NewSet[T comparable](items ...T) Set[T] { + return nil +} + +func (s Set[T]) Equals(other Set[T]) bool { + return EqualMap(s, other) +} + +func main() { + NewSet[Addr](Addr{0, 0, nil}) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51909.go b/platform/dbops/binaries/go/go/test/typeparam/issue51909.go new file mode 100644 index 0000000000000000000000000000000000000000..5fe39ca2b3b349bb8f5defa01dbd899cbd0c3a20 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51909.go @@ -0,0 +1,30 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type None struct{} + +type Response interface { + send(ctx *struct{}) +} + +type HandlerFunc[Input any] func(Input) Response + +func Operation[Input any](method, path string, h HandlerFunc[Input]) { + var input Input + h(input) +} + +func Get[Body any](path string, h HandlerFunc[struct{ Body Body }]) { + Operation("GET", path, h) +} + +func main() { + Get("/", func(req struct{ Body None }) Response { + return nil + }) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue51925.go b/platform/dbops/binaries/go/go/test/typeparam/issue51925.go new file mode 100644 index 0000000000000000000000000000000000000000..abebf6776613e219ab0a5d3bc06ef0e36981aa84 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue51925.go @@ -0,0 +1,51 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type IntLike interface { + ~int | ~int64 | ~int32 | ~int16 | ~int8 +} + +func Reduce[T any, U any, Uslice ~[]U](function func(T, U) T, sequence Uslice, initial T) T { + result := initial + for _, x := range sequence { + result = function(result, x) + } + return result +} + +func min[T IntLike](x, y T) T { + if x < y { + return x + } + return y +} + +// Min returns the minimum element of `nums`. +func Min[T IntLike, NumSlice ~[]T](nums NumSlice) T { + if len(nums) == 0 { + return T(0) + } + return Reduce(min[T], nums, nums[0]) +} + +// VarMin is the variadic version of Min. +func VarMin[T IntLike](nums ...T) T { + return Min(nums) +} + +type myInt int + +func main() { + fmt.Println(VarMin(myInt(1), myInt(2))) + + seq := []myInt{1, 2} + fmt.Println(Min(seq)) + fmt.Println(VarMin(seq...)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue52026.go b/platform/dbops/binaries/go/go/test/typeparam/issue52026.go new file mode 100644 index 0000000000000000000000000000000000000000..db8999a2b09eb1f45ac0669a43eb98125e8374fb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue52026.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func returnOption[T any](n int) Option[T] { + if n == 1 { + return Some[T]{} + } else { + return None{} + } +} + +type Option[T any] interface { + sealedOption() +} + +type Some[T any] struct { + val T +} + +func (s Some[T]) Value() T { + return s.val +} + +func (s Some[T]) sealedOption() {} + +type None struct{} + +func (s None) sealedOption() {} + +func main() { + s := returnOption[int](1) + _ = s.(Some[int]) + + s = returnOption[int](0) + _ = s.(None) + + switch (any)(s).(type) { + case Some[int]: + panic("s is a Some[int]") + case None: + // ok + default: + panic("oops") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue52117.go b/platform/dbops/binaries/go/go/test/typeparam/issue52117.go new file mode 100644 index 0000000000000000000000000000000000000000..8bb5c3e21398f4d28cfb34ab6acd869926063c1c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue52117.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue52124.go b/platform/dbops/binaries/go/go/test/typeparam/issue52124.go new file mode 100644 index 0000000000000000000000000000000000000000..802d1039cab1b0dd8288d6b583ed4bfe295dc7c7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue52124.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type Any any +type IntOrBool interface{ int | bool } + +type I interface{ Any | IntOrBool } + +var ( + X I = 42 + Y I = "xxx" + Z I = true +) + +type A interface{ *B | int } +type B interface{ A | any } diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue52228.go b/platform/dbops/binaries/go/go/test/typeparam/issue52228.go new file mode 100644 index 0000000000000000000000000000000000000000..3fbbde59ab62a2384e82e109d6f46ce1e3deede3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue52228.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type SomeInterface interface { + Whatever() +} + +func X[T any]() T { + var m T + + // for this example, this block should never run + if _, ok := any(m).(SomeInterface); ok { + var dst SomeInterface + _, _ = dst.(T) + return dst.(T) + } + + return m +} + +type holder struct{} + +func main() { + X[holder]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue52241.go b/platform/dbops/binaries/go/go/test/typeparam/issue52241.go new file mode 100644 index 0000000000000000000000000000000000000000..4feb97e0131d07ec6e4769c3da73055acfd32082 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue52241.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Collector[T any] struct { +} + +func (c *Collector[T]) Collect() { +} + +func TestInOrderIntTree() { + collector := Collector[int]{} + _ = collector.Collect +} + +func main() { + TestInOrderIntTree() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53087.go b/platform/dbops/binaries/go/go/test/typeparam/issue53087.go new file mode 100644 index 0000000000000000000000000000000000000000..5e19c59f1f34a8ac28dba2da53f2ae2fe5ea42c8 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53087.go @@ -0,0 +1,56 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type I interface { + M() +} + +type S struct { + str string +} + +func (s *S) M() {} + +var _ I = &S{} + +type CloningMap[K comparable, V any] struct { + inner map[K]V +} + +func (cm CloningMap[K, V]) With(key K, value V) CloningMap[K, V] { + result := CloneBad(cm.inner) + result[key] = value + return CloningMap[K, V]{result} +} + +func CloneBad[M ~map[K]V, K comparable, V any](m M) M { + r := make(M, len(m)) + for k, v := range m { + r[k] = v + } + return r +} + +func main() { + s1 := &S{"one"} + s2 := &S{"two"} + + m := CloningMap[string, I]{inner: make(map[string]I)} + m = m.With("a", s1) + m = m.With("b", s2) + + it, found := m.inner["a"] + if !found { + panic("a not found") + } + if _, ok := it.(*S); !ok { + panic(fmt.Sprintf("got %T want *main.S", it)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53254.go b/platform/dbops/binaries/go/go/test/typeparam/issue53254.go new file mode 100644 index 0000000000000000000000000000000000000000..afc0f1847128779707d2e27a919290d3f8ba6586 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53254.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Interface[T any] interface { +} + +func F[T any]() Interface[T] { + var i int + return i +} + +func main() { + F[int]() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53390.go b/platform/dbops/binaries/go/go/test/typeparam/issue53390.go new file mode 100644 index 0000000000000000000000000000000000000000..52098c520b4b7e0f2589ccb30f0569fffbe1ed03 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53390.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +func F[T any](v T) uintptr { + return unsafe.Alignof(func() T { + func(any) {}(struct{ _ T }{}) + return v + }()) +} + +func f() { + F(0) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53406.go b/platform/dbops/binaries/go/go/test/typeparam/issue53406.go new file mode 100644 index 0000000000000000000000000000000000000000..90fe78fb6f57952391bff03d4cf9264b508f5664 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53406.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + f[int]() +} + +func f[T1 any]() { + var x Outer[T1, int] + x.M() +} + +type Outer[T1, T2 any] struct{ Inner[T2] } + +type Inner[_ any] int + +func (Inner[_]) M() {} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53419.go b/platform/dbops/binaries/go/go/test/typeparam/issue53419.go new file mode 100644 index 0000000000000000000000000000000000000000..62a226ff9f777d25f7f796764b5f74a31dd50a14 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53419.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T1 struct{} +type T2 struct{} +type Both struct { + T1 + T2 +} + +func (T1) m() { panic("FAIL") } +func (T2) m() { panic("FAIL") } +func (Both) m() {} + +func f[T interface{ m() }](c T) { + c.m() +} + +func main() { + var b Both + b.m() + f(b) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53477.go b/platform/dbops/binaries/go/go/test/typeparam/issue53477.go new file mode 100644 index 0000000000000000000000000000000000000000..d128a7e84876d7587d4ff69e25ef5483cedbf0c1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53477.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that generic interface-interface comparisons resulting from +// value switch statements are handled correctly. + +package main + +func main() { + f[X](0) +} + +type Mer[T any] interface{ M(T) } +type MNer[T any] interface { + Mer[T] + N() +} + +type X int + +func (X) M(X) {} +func (X) N() {} + +func f[T MNer[T]](t T) { + switch Mer[T](t) { + case MNer[T](t): + // ok + default: + panic("FAIL") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue53762.go b/platform/dbops/binaries/go/go/test/typeparam/issue53762.go new file mode 100644 index 0000000000000000000000000000000000000000..e6d7f0f9f3a9f0698202aa634f21a5b32e84809e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue53762.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Value[T any] interface { +} + +func use[T any](v Value[T]) { + _, _ = v.(int) +} + +func main() { + use[int](Value[int](1)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54135.go b/platform/dbops/binaries/go/go/test/typeparam/issue54135.go new file mode 100644 index 0000000000000000000000000000000000000000..b489a514165d234d8c9ca7b98b32b0956ce4bbf5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54135.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Foo struct{} + +func (Foo) Blanker() {} + +type Bar[T any] interface { + Blanker() +} + +type Baz interface { + Some() +} + +func check[T comparable](p Bar[T]) { + if x, ok := p.(any); !ok || x != p { + panic("FAIL") + } + if _, ok := p.(Baz); ok { + panic("FAIL") + } +} + +func main() { + check[int](Foo{}) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54225.go b/platform/dbops/binaries/go/go/test/typeparam/issue54225.go new file mode 100644 index 0000000000000000000000000000000000000000..4de3efcaaf973ac919f285b12f3f1bf31865f06d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54225.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + One[TextValue]() +} + +func One[V Value]() { Two[Node[V]]() } + +func Two[V interface{ contentLen() int }]() { + var v V + v.contentLen() +} + +type Value interface { + Len() int +} + +type Node[V Value] struct{} + +func (Node[V]) contentLen() int { + var value V + return value.Len() +} + +type TextValue struct{} + +func (TextValue) Len() int { return 0 } diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54302.go b/platform/dbops/binaries/go/go/test/typeparam/issue54302.go new file mode 100644 index 0000000000000000000000000000000000000000..f132421c84abfa23159290f97fee62f93d6c611c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54302.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54456.go b/platform/dbops/binaries/go/go/test/typeparam/issue54456.go new file mode 100644 index 0000000000000000000000000000000000000000..8342163e51d6433076b3e39eb7ebd8271ce820c6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54456.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The Go 1.18 frontend failed to disambiguate instantiations of +// different, locally defined generic types with the same name. +// +// The unified frontend also exposed the scope-disambiguation mangling +// to end users in reflect data. + +package main + +import ( + "reflect" +) + +func one() any { type T[_ any] int; return T[int](0) } +func two() any { type T[_ any] int; return T[int](0) } + +func main() { + p, q := one(), two() + + // p and q have different dynamic types; this comparison should + // evaluate false. + if p == q { + panic("bad type identity") + } + + for _, x := range []any{p, q} { + // The names here should not contain "·1" or "·2". + if name := reflect.TypeOf(x).String(); name != "main.T[int]" { + panic(name) + } + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54497.go b/platform/dbops/binaries/go/go/test/typeparam/issue54497.go new file mode 100644 index 0000000000000000000000000000000000000000..1b24cd9afb6b22ea152434b9daf04444551c5ccc --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54497.go @@ -0,0 +1,19 @@ +// errorcheck -0 -m + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that inlining works with generic functions. + +package testcase + +type C interface{ ~uint | ~uint32 | ~uint64 } + +func isAligned[T C](x, y T) bool { // ERROR "can inline isAligned\[uint\]" "can inline isAligned\[go\.shape\.uint\]" "inlining call to isAligned\[go\.shape\.uint\]" + return x%y == 0 +} + +func foo(x uint) bool { // ERROR "can inline foo" + return isAligned(x, 64) // ERROR "inlining call to isAligned\[go\.shape\.uint\]" +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54535.go b/platform/dbops/binaries/go/go/test/typeparam/issue54535.go new file mode 100644 index 0000000000000000000000000000000000000000..574b2755986ba2ebc7530bd0e1ba122fc4d07234 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54535.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type node[T any] struct { + items items[T] + children items[*node[T]] +} + +func (n *node[T]) f(i int, j int) bool { + if len(n.children[i].items) < j { + return false + } + return true +} + +type items[T any] []T + +func main() { + _ = node[int]{} + _ = f[int] +} + +type s[T, U any] struct { + a T + c U +} + +func f[T any]() { + var x s[*struct{ b T }, *struct{ d int }] + _ = x.a.b + _ = x.c.d +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54537.go b/platform/dbops/binaries/go/go/test/typeparam/issue54537.go new file mode 100644 index 0000000000000000000000000000000000000000..614ed4648d509785c5b41bee9db647b51a1c6ac4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54537.go @@ -0,0 +1,22 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + _ = F[bool] + + var x string + _ = G(x == "foo") +} + +func F[T ~bool](x string) { + var _ T = x == "foo" +} + +func G[T any](t T) *T { + return &t +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue54765.go b/platform/dbops/binaries/go/go/test/typeparam/issue54765.go new file mode 100644 index 0000000000000000000000000000000000000000..69a0d3746d9651da07a2fe38f78e55889d18f99a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue54765.go @@ -0,0 +1,27 @@ +// errorcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that not-in-heap types cannot be used as type +// arguments. (pointer-to-nih types are okay though.) + +//go:build cgo + +package p + +import ( + "runtime/cgo" + "sync/atomic" +) + +var _ atomic.Pointer[cgo.Incomplete] // ERROR "cannot use incomplete \(or unallocatable\) type as a type argument: runtime/cgo\.Incomplete" +var _ atomic.Pointer[*cgo.Incomplete] // ok + +func implicit(ptr *cgo.Incomplete) { + g(ptr) // ERROR "cannot use incomplete \(or unallocatable\) type as a type argument: runtime/cgo\.Incomplete" + g(&ptr) // ok +} + +func g[T any](_ *T) {} diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue55101.go b/platform/dbops/binaries/go/go/test/typeparam/issue55101.go new file mode 100644 index 0000000000000000000000000000000000000000..2d45c87a28b6a24cb398d9cab91204af65544e1b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue55101.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func F() *Cache[error] { return nil } + +type Cache[T any] struct{ l *List[entry[T]] } +type entry[T any] struct{ value T } +type List[T any] struct{ len int } + +func (c *Cache[V]) Len() int { return c.l.Len() } +func (l *List[T]) Len() int { return l.len } diff --git a/platform/dbops/binaries/go/go/test/typeparam/issue58513.go b/platform/dbops/binaries/go/go/test/typeparam/issue58513.go new file mode 100644 index 0000000000000000000000000000000000000000..37cb5725ca14c0e8cb2847f104a398d7ec9aa19c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/issue58513.go @@ -0,0 +1,60 @@ +// run + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Some derived-type expressions require the compiler to synthesize +// function literals to plumb sub-dictionaries appropriately. +// However, when these expressions are inlined, we were constructing +// the function literal bodies with the inline-adjusted positions +// instead of the original (inline-free) positions, which could lead +// to infinite loops when unwinding the stack. + +package main + +import "runtime" + +func assert[_ any]() { + panic(0) +} + +func Assert[To any]() func() { + return assert[To] +} + +type asserter[_ any] struct{} + +func (asserter[_]) assert() { + panic(0) +} + +func AssertMV[To any]() func() { + return asserter[To]{}.assert +} + +func AssertME[To any]() func(asserter[To]) { + return asserter[To].assert +} + +var me = AssertME[string]() + +var tests = []func(){ + Assert[int](), + AssertMV[int](), + func() { me(asserter[string]{}) }, +} + +func main() { + for _, test := range tests { + func() { + defer func() { + recover() + + // Check that we can unwind the stack without infinite looping. + runtime.Caller(1000) + }() + test() + }() + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/list.go b/platform/dbops/binaries/go/go/test/typeparam/list.go new file mode 100644 index 0000000000000000000000000000000000000000..34ad71c4999a3fb9cc44e35140ddfea74ca6d1d4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/list.go @@ -0,0 +1,103 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +// _List is a linked list of ordered values of type T. +type _List[T Ordered] struct { + next *_List[T] + val T +} + +func (l *_List[T]) Largest() T { + var max T + for p := l; p != nil; p = p.next { + if p.val > max { + max = p.val + } + } + return max +} + +type OrderedNum interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 +} + +// _ListNum is a linked _List of ordered numeric values of type T. +type _ListNum[T OrderedNum] struct { + next *_ListNum[T] + val T +} + +const Clip = 5 + +// ClippedLargest returns the largest in the list of OrderNums, but a max of 5. +// Test use of untyped constant in an expression with a generically-typed parameter +func (l *_ListNum[T]) ClippedLargest() T { + var max T + for p := l; p != nil; p = p.next { + if p.val > max && p.val < Clip { + max = p.val + } + } + return max +} + +func main() { + i3 := &_List[int]{nil, 1} + i2 := &_List[int]{i3, 3} + i1 := &_List[int]{i2, 2} + if got, want := i1.Largest(), 3; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + b3 := &_List[byte]{nil, byte(1)} + b2 := &_List[byte]{b3, byte(3)} + b1 := &_List[byte]{b2, byte(2)} + if got, want := b1.Largest(), byte(3); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + f3 := &_List[float64]{nil, 13.5} + f2 := &_List[float64]{f3, 1.2} + f1 := &_List[float64]{f2, 4.5} + if got, want := f1.Largest(), 13.5; got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } + + s3 := &_List[string]{nil, "dd"} + s2 := &_List[string]{s3, "aa"} + s1 := &_List[string]{s2, "bb"} + if got, want := s1.Largest(), "dd"; got != want { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + j3 := &_ListNum[int]{nil, 1} + j2 := &_ListNum[int]{j3, 32} + j1 := &_ListNum[int]{j2, 2} + if got, want := j1.ClippedLargest(), 2; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + g3 := &_ListNum[float64]{nil, 13.5} + g2 := &_ListNum[float64]{g3, 1.2} + g1 := &_ListNum[float64]{g2, 4.5} + if got, want := g1.ClippedLargest(), 4.5; got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/list2.go b/platform/dbops/binaries/go/go/test/typeparam/list2.go new file mode 100644 index 0000000000000000000000000000000000000000..111ac787e509d047dc7d612c47fb32691a88b9ec --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/list2.go @@ -0,0 +1,608 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package list provides a doubly linked list of some element type +// (generic form of the "container/list" package). + +package main + +import ( + "fmt" + "strconv" +) + +// Element is an element of a linked list. +type _Element[T any] struct { + // Next and previous pointers in the doubly-linked list of elements. + // To simplify the implementation, internally a list l is implemented + // as a ring, such that &l.root is both the next element of the last + // list element (l.Back()) and the previous element of the first list + // element (l.Front()). + next, prev *_Element[T] + + // The list to which this element belongs. + list *_List[T] + + // The value stored with this element. + Value T +} + +// Next returns the next list element or nil. +func (e *_Element[T]) Next() *_Element[T] { + if p := e.next; e.list != nil && p != &e.list.root { + return p + } + return nil +} + +// Prev returns the previous list element or nil. +func (e *_Element[T]) Prev() *_Element[T] { + if p := e.prev; e.list != nil && p != &e.list.root { + return p + } + return nil +} + +// _List represents a doubly linked list. +// The zero value for _List is an empty list ready to use. +type _List[T any] struct { + root _Element[T] // sentinel list element, only &root, root.prev, and root.next are used + len int // current list length excluding (this) sentinel element +} + +// Init initializes or clears list l. +func (l *_List[T]) Init() *_List[T] { + l.root.next = &l.root + l.root.prev = &l.root + l.len = 0 + return l +} + +// New returns an initialized list. +func _New[T any]() *_List[T] { return new(_List[T]).Init() } + +// Len returns the number of elements of list l. +// The complexity is O(1). +func (l *_List[_]) Len() int { return l.len } + +// Front returns the first element of list l or nil if the list is empty. +func (l *_List[T]) Front() *_Element[T] { + if l.len == 0 { + return nil + } + return l.root.next +} + +// Back returns the last element of list l or nil if the list is empty. +func (l *_List[T]) Back() *_Element[T] { + if l.len == 0 { + return nil + } + return l.root.prev +} + +// lazyInit lazily initializes a zero _List value. +func (l *_List[_]) lazyInit() { + if l.root.next == nil { + l.Init() + } +} + +// insert inserts e after at, increments l.len, and returns e. +func (l *_List[T]) insert(e, at *_Element[T]) *_Element[T] { + e.prev = at + e.next = at.next + e.prev.next = e + e.next.prev = e + e.list = l + l.len++ + return e +} + +// insertValue is a convenience wrapper for insert(&_Element[T]{Value: v}, at). +func (l *_List[T]) insertValue(v T, at *_Element[T]) *_Element[T] { + return l.insert(&_Element[T]{Value: v}, at) +} + +// remove removes e from its list, decrements l.len, and returns e. +func (l *_List[T]) remove(e *_Element[T]) *_Element[T] { + e.prev.next = e.next + e.next.prev = e.prev + e.next = nil // avoid memory leaks + e.prev = nil // avoid memory leaks + e.list = nil + l.len-- + return e +} + +// move moves e to next to at and returns e. +func (l *_List[T]) move(e, at *_Element[T]) *_Element[T] { + if e == at { + return e + } + e.prev.next = e.next + e.next.prev = e.prev + + e.prev = at + e.next = at.next + e.prev.next = e + e.next.prev = e + + return e +} + +// Remove removes e from l if e is an element of list l. +// It returns the element value e.Value. +// The element must not be nil. +func (l *_List[T]) Remove(e *_Element[T]) T { + if e.list == l { + // if e.list == l, l must have been initialized when e was inserted + // in l or l == nil (e is a zero _Element) and l.remove will crash + l.remove(e) + } + return e.Value +} + +// PushFront inserts a new element e with value v at the front of list l and returns e. +func (l *_List[T]) PushFront(v T) *_Element[T] { + l.lazyInit() + return l.insertValue(v, &l.root) +} + +// PushBack inserts a new element e with value v at the back of list l and returns e. +func (l *_List[T]) PushBack(v T) *_Element[T] { + l.lazyInit() + return l.insertValue(v, l.root.prev) +} + +// InsertBefore inserts a new element e with value v immediately before mark and returns e. +// If mark is not an element of l, the list is not modified. +// The mark must not be nil. +func (l *_List[T]) InsertBefore(v T, mark *_Element[T]) *_Element[T] { + if mark.list != l { + return nil + } + // see comment in _List.Remove about initialization of l + return l.insertValue(v, mark.prev) +} + +// InsertAfter inserts a new element e with value v immediately after mark and returns e. +// If mark is not an element of l, the list is not modified. +// The mark must not be nil. +func (l *_List[T]) InsertAfter(v T, mark *_Element[T]) *_Element[T] { + if mark.list != l { + return nil + } + // see comment in _List.Remove about initialization of l + return l.insertValue(v, mark) +} + +// MoveToFront moves element e to the front of list l. +// If e is not an element of l, the list is not modified. +// The element must not be nil. +func (l *_List[T]) MoveToFront(e *_Element[T]) { + if e.list != l || l.root.next == e { + return + } + // see comment in _List.Remove about initialization of l + l.move(e, &l.root) +} + +// MoveToBack moves element e to the back of list l. +// If e is not an element of l, the list is not modified. +// The element must not be nil. +func (l *_List[T]) MoveToBack(e *_Element[T]) { + if e.list != l || l.root.prev == e { + return + } + // see comment in _List.Remove about initialization of l + l.move(e, l.root.prev) +} + +// MoveBefore moves element e to its new position before mark. +// If e or mark is not an element of l, or e == mark, the list is not modified. +// The element and mark must not be nil. +func (l *_List[T]) MoveBefore(e, mark *_Element[T]) { + if e.list != l || e == mark || mark.list != l { + return + } + l.move(e, mark.prev) +} + +// MoveAfter moves element e to its new position after mark. +// If e or mark is not an element of l, or e == mark, the list is not modified. +// The element and mark must not be nil. +func (l *_List[T]) MoveAfter(e, mark *_Element[T]) { + if e.list != l || e == mark || mark.list != l { + return + } + l.move(e, mark) +} + +// PushBackList inserts a copy of an other list at the back of list l. +// The lists l and other may be the same. They must not be nil. +func (l *_List[T]) PushBackList(other *_List[T]) { + l.lazyInit() + for i, e := other.Len(), other.Front(); i > 0; i, e = i-1, e.Next() { + l.insertValue(e.Value, l.root.prev) + } +} + +// PushFrontList inserts a copy of an other list at the front of list l. +// The lists l and other may be the same. They must not be nil. +func (l *_List[T]) PushFrontList(other *_List[T]) { + l.lazyInit() + for i, e := other.Len(), other.Back(); i > 0; i, e = i-1, e.Prev() { + l.insertValue(e.Value, &l.root) + } +} + +// Transform runs a transform function on a list returning a new list. +func _Transform[TElem1, TElem2 any](lst *_List[TElem1], f func(TElem1) TElem2) *_List[TElem2] { + ret := _New[TElem2]() + for p := lst.Front(); p != nil; p = p.Next() { + ret.PushBack(f(p.Value)) + } + return ret +} + +func checkListLen[T any](l *_List[T], len int) bool { + if n := l.Len(); n != len { + panic(fmt.Sprintf("l.Len() = %d, want %d", n, len)) + return false + } + return true +} + +func checkListPointers[T any](l *_List[T], es []*_Element[T]) { + root := &l.root + + if !checkListLen(l, len(es)) { + return + } + + // zero length lists must be the zero value or properly initialized (sentinel circle) + if len(es) == 0 { + if l.root.next != nil && l.root.next != root || l.root.prev != nil && l.root.prev != root { + panic(fmt.Sprintf("l.root.next = %p, l.root.prev = %p; both should both be nil or %p", l.root.next, l.root.prev, root)) + } + return + } + // len(es) > 0 + + // check internal and external prev/next connections + for i, e := range es { + prev := root + Prev := (*_Element[T])(nil) + if i > 0 { + prev = es[i-1] + Prev = prev + } + if p := e.prev; p != prev { + panic(fmt.Sprintf("elt[%d](%p).prev = %p, want %p", i, e, p, prev)) + } + if p := e.Prev(); p != Prev { + panic(fmt.Sprintf("elt[%d](%p).Prev() = %p, want %p", i, e, p, Prev)) + } + + next := root + Next := (*_Element[T])(nil) + if i < len(es)-1 { + next = es[i+1] + Next = next + } + if n := e.next; n != next { + panic(fmt.Sprintf("elt[%d](%p).next = %p, want %p", i, e, n, next)) + } + if n := e.Next(); n != Next { + panic(fmt.Sprintf("elt[%d](%p).Next() = %p, want %p", i, e, n, Next)) + } + } +} + +func TestList() { + l := _New[string]() + checkListPointers(l, []*(_Element[string]){}) + + // Single element list + e := l.PushFront("a") + checkListPointers(l, []*(_Element[string]){e}) + l.MoveToFront(e) + checkListPointers(l, []*(_Element[string]){e}) + l.MoveToBack(e) + checkListPointers(l, []*(_Element[string]){e}) + l.Remove(e) + checkListPointers(l, []*(_Element[string]){}) + + // Bigger list + l2 := _New[int]() + e2 := l2.PushFront(2) + e1 := l2.PushFront(1) + e3 := l2.PushBack(3) + e4 := l2.PushBack(600) + checkListPointers(l2, []*(_Element[int]){e1, e2, e3, e4}) + + l2.Remove(e2) + checkListPointers(l2, []*(_Element[int]){e1, e3, e4}) + + l2.MoveToFront(e3) // move from middle + checkListPointers(l2, []*(_Element[int]){e3, e1, e4}) + + l2.MoveToFront(e1) + l2.MoveToBack(e3) // move from middle + checkListPointers(l2, []*(_Element[int]){e1, e4, e3}) + + l2.MoveToFront(e3) // move from back + checkListPointers(l2, []*(_Element[int]){e3, e1, e4}) + l2.MoveToFront(e3) // should be no-op + checkListPointers(l2, []*(_Element[int]){e3, e1, e4}) + + l2.MoveToBack(e3) // move from front + checkListPointers(l2, []*(_Element[int]){e1, e4, e3}) + l2.MoveToBack(e3) // should be no-op + checkListPointers(l2, []*(_Element[int]){e1, e4, e3}) + + e2 = l2.InsertBefore(2, e1) // insert before front + checkListPointers(l2, []*(_Element[int]){e2, e1, e4, e3}) + l2.Remove(e2) + e2 = l2.InsertBefore(2, e4) // insert before middle + checkListPointers(l2, []*(_Element[int]){e1, e2, e4, e3}) + l2.Remove(e2) + e2 = l2.InsertBefore(2, e3) // insert before back + checkListPointers(l2, []*(_Element[int]){e1, e4, e2, e3}) + l2.Remove(e2) + + e2 = l2.InsertAfter(2, e1) // insert after front + checkListPointers(l2, []*(_Element[int]){e1, e2, e4, e3}) + l2.Remove(e2) + e2 = l2.InsertAfter(2, e4) // insert after middle + checkListPointers(l2, []*(_Element[int]){e1, e4, e2, e3}) + l2.Remove(e2) + e2 = l2.InsertAfter(2, e3) // insert after back + checkListPointers(l2, []*(_Element[int]){e1, e4, e3, e2}) + l2.Remove(e2) + + // Check standard iteration. + sum := 0 + for e := l2.Front(); e != nil; e = e.Next() { + sum += e.Value + } + if sum != 604 { + panic(fmt.Sprintf("sum over l = %d, want 604", sum)) + } + + // Clear all elements by iterating + var next *_Element[int] + for e := l2.Front(); e != nil; e = next { + next = e.Next() + l2.Remove(e) + } + checkListPointers(l2, []*(_Element[int]){}) +} + +func checkList[T comparable](l *_List[T], es []interface{}) { + if !checkListLen(l, len(es)) { + return + } + + i := 0 + for e := l.Front(); e != nil; e = e.Next() { + le := e.Value + // Comparison between a generically-typed variable le and an interface. + if le != es[i] { + panic(fmt.Sprintf("elt[%d].Value = %v, want %v", i, le, es[i])) + } + i++ + } +} + +func TestExtending() { + l1 := _New[int]() + l2 := _New[int]() + + l1.PushBack(1) + l1.PushBack(2) + l1.PushBack(3) + + l2.PushBack(4) + l2.PushBack(5) + + l3 := _New[int]() + l3.PushBackList(l1) + checkList(l3, []interface{}{1, 2, 3}) + l3.PushBackList(l2) + checkList(l3, []interface{}{1, 2, 3, 4, 5}) + + l3 = _New[int]() + l3.PushFrontList(l2) + checkList(l3, []interface{}{4, 5}) + l3.PushFrontList(l1) + checkList(l3, []interface{}{1, 2, 3, 4, 5}) + + checkList(l1, []interface{}{1, 2, 3}) + checkList(l2, []interface{}{4, 5}) + + l3 = _New[int]() + l3.PushBackList(l1) + checkList(l3, []interface{}{1, 2, 3}) + l3.PushBackList(l3) + checkList(l3, []interface{}{1, 2, 3, 1, 2, 3}) + + l3 = _New[int]() + l3.PushFrontList(l1) + checkList(l3, []interface{}{1, 2, 3}) + l3.PushFrontList(l3) + checkList(l3, []interface{}{1, 2, 3, 1, 2, 3}) + + l3 = _New[int]() + l1.PushBackList(l3) + checkList(l1, []interface{}{1, 2, 3}) + l1.PushFrontList(l3) + checkList(l1, []interface{}{1, 2, 3}) +} + +func TestRemove() { + l := _New[int]() + e1 := l.PushBack(1) + e2 := l.PushBack(2) + checkListPointers(l, []*(_Element[int]){e1, e2}) + e := l.Front() + l.Remove(e) + checkListPointers(l, []*(_Element[int]){e2}) + l.Remove(e) + checkListPointers(l, []*(_Element[int]){e2}) +} + +func TestIssue4103() { + l1 := _New[int]() + l1.PushBack(1) + l1.PushBack(2) + + l2 := _New[int]() + l2.PushBack(3) + l2.PushBack(4) + + e := l1.Front() + l2.Remove(e) // l2 should not change because e is not an element of l2 + if n := l2.Len(); n != 2 { + panic(fmt.Sprintf("l2.Len() = %d, want 2", n)) + } + + l1.InsertBefore(8, e) + if n := l1.Len(); n != 3 { + panic(fmt.Sprintf("l1.Len() = %d, want 3", n)) + } +} + +func TestIssue6349() { + l := _New[int]() + l.PushBack(1) + l.PushBack(2) + + e := l.Front() + l.Remove(e) + if e.Value != 1 { + panic(fmt.Sprintf("e.value = %d, want 1", e.Value)) + } + if e.Next() != nil { + panic(fmt.Sprintf("e.Next() != nil")) + } + if e.Prev() != nil { + panic(fmt.Sprintf("e.Prev() != nil")) + } +} + +func TestMove() { + l := _New[int]() + e1 := l.PushBack(1) + e2 := l.PushBack(2) + e3 := l.PushBack(3) + e4 := l.PushBack(4) + + l.MoveAfter(e3, e3) + checkListPointers(l, []*(_Element[int]){e1, e2, e3, e4}) + l.MoveBefore(e2, e2) + checkListPointers(l, []*(_Element[int]){e1, e2, e3, e4}) + + l.MoveAfter(e3, e2) + checkListPointers(l, []*(_Element[int]){e1, e2, e3, e4}) + l.MoveBefore(e2, e3) + checkListPointers(l, []*(_Element[int]){e1, e2, e3, e4}) + + l.MoveBefore(e2, e4) + checkListPointers(l, []*(_Element[int]){e1, e3, e2, e4}) + e2, e3 = e3, e2 + + l.MoveBefore(e4, e1) + checkListPointers(l, []*(_Element[int]){e4, e1, e2, e3}) + e1, e2, e3, e4 = e4, e1, e2, e3 + + l.MoveAfter(e4, e1) + checkListPointers(l, []*(_Element[int]){e1, e4, e2, e3}) + e2, e3, e4 = e4, e2, e3 + + l.MoveAfter(e2, e3) + checkListPointers(l, []*(_Element[int]){e1, e3, e2, e4}) + e2, e3 = e3, e2 +} + +// Test PushFront, PushBack, PushFrontList, PushBackList with uninitialized _List +func TestZeroList() { + var l1 = new(_List[int]) + l1.PushFront(1) + checkList(l1, []interface{}{1}) + + var l2 = new(_List[int]) + l2.PushBack(1) + checkList(l2, []interface{}{1}) + + var l3 = new(_List[int]) + l3.PushFrontList(l1) + checkList(l3, []interface{}{1}) + + var l4 = new(_List[int]) + l4.PushBackList(l2) + checkList(l4, []interface{}{1}) +} + +// Test that a list l is not modified when calling InsertBefore with a mark that is not an element of l. +func TestInsertBeforeUnknownMark() { + var l _List[int] + l.PushBack(1) + l.PushBack(2) + l.PushBack(3) + l.InsertBefore(1, new(_Element[int])) + checkList(&l, []interface{}{1, 2, 3}) +} + +// Test that a list l is not modified when calling InsertAfter with a mark that is not an element of l. +func TestInsertAfterUnknownMark() { + var l _List[int] + l.PushBack(1) + l.PushBack(2) + l.PushBack(3) + l.InsertAfter(1, new(_Element[int])) + checkList(&l, []interface{}{1, 2, 3}) +} + +// Test that a list l is not modified when calling MoveAfter or MoveBefore with a mark that is not an element of l. +func TestMoveUnknownMark() { + var l1 _List[int] + e1 := l1.PushBack(1) + + var l2 _List[int] + e2 := l2.PushBack(2) + + l1.MoveAfter(e1, e2) + checkList(&l1, []interface{}{1}) + checkList(&l2, []interface{}{2}) + + l1.MoveBefore(e1, e2) + checkList(&l1, []interface{}{1}) + checkList(&l2, []interface{}{2}) +} + +// Test the Transform function. +func TestTransform() { + l1 := _New[int]() + l1.PushBack(1) + l1.PushBack(2) + l2 := _Transform(l1, strconv.Itoa) + checkList(l2, []interface{}{"1", "2"}) +} + +func main() { + TestList() + TestExtending() + TestRemove() + TestIssue4103() + TestIssue6349() + TestMove() + TestZeroList() + TestInsertBeforeUnknownMark() + TestInsertAfterUnknownMark() + TestTransform() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/listimp.go b/platform/dbops/binaries/go/go/test/typeparam/listimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/listimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/listimp2.go b/platform/dbops/binaries/go/go/test/typeparam/listimp2.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/listimp2.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/lockable.go b/platform/dbops/binaries/go/go/test/typeparam/lockable.go new file mode 100644 index 0000000000000000000000000000000000000000..2b50e2c20e8bef252ace6ae03b27b50bcf627958 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/lockable.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "sync" + +// A Lockable is a value that may be safely simultaneously accessed +// from multiple goroutines via the Get and Set methods. +type Lockable[T any] struct { + x T + mu sync.Mutex +} + +// Get returns the value stored in a Lockable. +func (l *Lockable[T]) get() T { + l.mu.Lock() + defer l.mu.Unlock() + return l.x +} + +// set sets the value in a Lockable. +func (l *Lockable[T]) set(v T) { + l.mu.Lock() + defer l.mu.Unlock() + l.x = v +} + +func main() { + sl := Lockable[string]{x: "a"} + if got := sl.get(); got != "a" { + panic(got) + } + sl.set("b") + if got := sl.get(); got != "b" { + panic(got) + } + + il := Lockable[int]{x: 1} + if got := il.get(); got != 1 { + panic(got) + } + il.set(2) + if got := il.get(); got != 2 { + panic(got) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/map.go b/platform/dbops/binaries/go/go/test/typeparam/map.go new file mode 100644 index 0000000000000000000000000000000000000000..eb68fe5c334f29683cc02a619324fd8e5cb09bc5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/map.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "reflect" + "strconv" +) + +// Map calls the function f on every element of the slice s, +// returning a new slice of the results. +func mapper[F, T any](s []F, f func(F) T) []T { + r := make([]T, len(s)) + for i, v := range s { + r[i] = f(v) + } + return r +} + +func main() { + got := mapper([]int{1, 2, 3}, strconv.Itoa) + want := []string{"1", "2", "3"} + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + fgot := mapper([]float64{2.5, 2.3, 3.5}, func(f float64) string { + return strconv.FormatFloat(f, 'f', -1, 64) + }) + fwant := []string{"2.5", "2.3", "3.5"} + if !reflect.DeepEqual(fgot, fwant) { + panic(fmt.Sprintf("got %s, want %s", fgot, fwant)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/mapimp.go b/platform/dbops/binaries/go/go/test/typeparam/mapimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/mapimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/maps.go b/platform/dbops/binaries/go/go/test/typeparam/maps.go new file mode 100644 index 0000000000000000000000000000000000000000..d4be5dd0f4fe090da7417721ea146889bce29fdd --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/maps.go @@ -0,0 +1,260 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "math" + "sort" +) + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// _Keys returns the keys of the map m. +// The keys will be an indeterminate order. +func _Keys[K comparable, V any](m map[K]V) []K { + r := make([]K, 0, len(m)) + for k := range m { + r = append(r, k) + } + return r +} + +// _Values returns the values of the map m. +// The values will be in an indeterminate order. +func _Values[K comparable, V any](m map[K]V) []V { + r := make([]V, 0, len(m)) + for _, v := range m { + r = append(r, v) + } + return r +} + +// _Equal reports whether two maps contain the same key/value pairs. +// _Values are compared using ==. +func _Equal[K, V comparable](m1, m2 map[K]V) bool { + if len(m1) != len(m2) { + return false + } + for k, v1 := range m1 { + if v2, ok := m2[k]; !ok || v1 != v2 { + return false + } + } + return true +} + +// _Copy returns a copy of m. +func _Copy[K comparable, V any](m map[K]V) map[K]V { + r := make(map[K]V, len(m)) + for k, v := range m { + r[k] = v + } + return r +} + +// _Add adds all key/value pairs in m2 to m1. _Keys in m2 that are already +// present in m1 will be overwritten with the value in m2. +func _Add[K comparable, V any](m1, m2 map[K]V) { + for k, v := range m2 { + m1[k] = v + } +} + +// _Sub removes all keys in m2 from m1. _Keys in m2 that are not present +// in m1 are ignored. The values in m2 are ignored. +func _Sub[K comparable, V any](m1, m2 map[K]V) { + for k := range m2 { + delete(m1, k) + } +} + +// _Intersect removes all keys from m1 that are not present in m2. +// _Keys in m2 that are not in m1 are ignored. The values in m2 are ignored. +func _Intersect[K comparable, V any](m1, m2 map[K]V) { + for k := range m1 { + if _, ok := m2[k]; !ok { + delete(m1, k) + } + } +} + +// _Filter deletes any key/value pairs from m for which f returns false. +func _Filter[K comparable, V any](m map[K]V, f func(K, V) bool) { + for k, v := range m { + if !f(k, v) { + delete(m, k) + } + } +} + +// _TransformValues applies f to each value in m. The keys remain unchanged. +func _TransformValues[K comparable, V any](m map[K]V, f func(V) V) { + for k, v := range m { + m[k] = f(v) + } +} + +var m1 = map[int]int{1: 2, 2: 4, 4: 8, 8: 16} +var m2 = map[int]string{1: "2", 2: "4", 4: "8", 8: "16"} + +func TestKeys() { + want := []int{1, 2, 4, 8} + + got1 := _Keys(m1) + sort.Ints(got1) + if !_SliceEqual(got1, want) { + panic(fmt.Sprintf("_Keys(%v) = %v, want %v", m1, got1, want)) + } + + got2 := _Keys(m2) + sort.Ints(got2) + if !_SliceEqual(got2, want) { + panic(fmt.Sprintf("_Keys(%v) = %v, want %v", m2, got2, want)) + } +} + +func TestValues() { + got1 := _Values(m1) + want1 := []int{2, 4, 8, 16} + sort.Ints(got1) + if !_SliceEqual(got1, want1) { + panic(fmt.Sprintf("_Values(%v) = %v, want %v", m1, got1, want1)) + } + + got2 := _Values(m2) + want2 := []string{"16", "2", "4", "8"} + sort.Strings(got2) + if !_SliceEqual(got2, want2) { + panic(fmt.Sprintf("_Values(%v) = %v, want %v", m2, got2, want2)) + } +} + +func TestEqual() { + if !_Equal(m1, m1) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", m1, m1)) + } + if _Equal(m1, nil) { + panic(fmt.Sprintf("_Equal(%v, nil) = true, want false", m1)) + } + if _Equal(nil, m1) { + panic(fmt.Sprintf("_Equal(nil, %v) = true, want false", m1)) + } + if !_Equal[int, int](nil, nil) { + panic("_Equal(nil, nil) = false, want true") + } + if ms := map[int]int{1: 2}; _Equal(m1, ms) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", m1, ms)) + } + + // Comparing NaN for equality is expected to fail. + mf := map[int]float64{1: 0, 2: math.NaN()} + if _Equal(mf, mf) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", mf, mf)) + } +} + +func TestCopy() { + m2 := _Copy(m1) + if !_Equal(m1, m2) { + panic(fmt.Sprintf("_Copy(%v) = %v, want %v", m1, m2, m1)) + } + m2[16] = 32 + if _Equal(m1, m2) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", m1, m2)) + } +} + +func TestAdd() { + mc := _Copy(m1) + _Add(mc, mc) + if !_Equal(mc, m1) { + panic(fmt.Sprintf("_Add(%v, %v) = %v, want %v", m1, m1, mc, m1)) + } + _Add(mc, map[int]int{16: 32}) + want := map[int]int{1: 2, 2: 4, 4: 8, 8: 16, 16: 32} + if !_Equal(mc, want) { + panic(fmt.Sprintf("_Add result = %v, want %v", mc, want)) + } +} + +func TestSub() { + mc := _Copy(m1) + _Sub(mc, mc) + if len(mc) > 0 { + panic(fmt.Sprintf("_Sub(%v, %v) = %v, want empty map", m1, m1, mc)) + } + mc = _Copy(m1) + _Sub(mc, map[int]int{1: 0}) + want := map[int]int{2: 4, 4: 8, 8: 16} + if !_Equal(mc, want) { + panic(fmt.Sprintf("_Sub result = %v, want %v", mc, want)) + } +} + +func TestIntersect() { + mc := _Copy(m1) + _Intersect(mc, mc) + if !_Equal(mc, m1) { + panic(fmt.Sprintf("_Intersect(%v, %v) = %v, want %v", m1, m1, mc, m1)) + } + _Intersect(mc, map[int]int{1: 0, 2: 0}) + want := map[int]int{1: 2, 2: 4} + if !_Equal(mc, want) { + panic(fmt.Sprintf("_Intersect result = %v, want %v", mc, want)) + } +} + +func TestFilter() { + mc := _Copy(m1) + _Filter(mc, func(int, int) bool { return true }) + if !_Equal(mc, m1) { + panic(fmt.Sprintf("_Filter(%v, true) = %v, want %v", m1, mc, m1)) + } + _Filter(mc, func(k, v int) bool { return k < 3 }) + want := map[int]int{1: 2, 2: 4} + if !_Equal(mc, want) { + panic(fmt.Sprintf("_Filter result = %v, want %v", mc, want)) + } +} + +func TestTransformValues() { + mc := _Copy(m1) + _TransformValues(mc, func(i int) int { return i / 2 }) + want := map[int]int{1: 1, 2: 2, 4: 4, 8: 8} + if !_Equal(mc, want) { + panic(fmt.Sprintf("_TransformValues result = %v, want %v", mc, want)) + } +} + +func main() { + TestKeys() + TestValues() + TestEqual() + TestCopy() + TestAdd() + TestSub() + TestIntersect() + TestFilter() + TestTransformValues() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/mapsimp.go b/platform/dbops/binaries/go/go/test/typeparam/mapsimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/mapsimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/metrics.go b/platform/dbops/binaries/go/go/test/typeparam/metrics.go new file mode 100644 index 0000000000000000000000000000000000000000..dcc5737a66f36d1cfe3f39bfa6010d901d113942 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/metrics.go @@ -0,0 +1,196 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package metrics provides tracking arbitrary metrics composed of +// values of comparable types. +package main + +import ( + "fmt" + "sort" + "sync" +) + +// _Metric1 tracks metrics of values of some type. +type _Metric1[T comparable] struct { + mu sync.Mutex + m map[T]int +} + +// Add adds another instance of some value. +func (m *_Metric1[T]) Add(v T) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[T]int) + } + m.m[v]++ +} + +// Count returns the number of instances we've seen of v. +func (m *_Metric1[T]) Count(v T) int { + m.mu.Lock() + defer m.mu.Unlock() + return m.m[v] +} + +// Metrics returns all the values we've seen, in an indeterminate order. +func (m *_Metric1[T]) Metrics() []T { + return _Keys(m.m) +} + +type key2[T1, T2 comparable] struct { + f1 T1 + f2 T2 +} + +// _Metric2 tracks metrics of pairs of values. +type _Metric2[T1, T2 comparable] struct { + mu sync.Mutex + m map[key2[T1, T2]]int +} + +// Add adds another instance of some pair of values. +func (m *_Metric2[T1, T2]) Add(v1 T1, v2 T2) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[key2[T1, T2]]int) + } + m.m[key2[T1, T2]{v1, v2}]++ +} + +// Count returns the number of instances we've seen of v1/v2. +func (m *_Metric2[T1, T2]) Count(v1 T1, v2 T2) int { + m.mu.Lock() + defer m.mu.Unlock() + return m.m[key2[T1, T2]{v1, v2}] +} + +// Metrics returns all the values we've seen, in an indeterminate order. +func (m *_Metric2[T1, T2]) Metrics() (r1 []T1, r2 []T2) { + for _, k := range _Keys(m.m) { + r1 = append(r1, k.f1) + r2 = append(r2, k.f2) + } + return r1, r2 +} + +type key3[T1, T2, T3 comparable] struct { + f1 T1 + f2 T2 + f3 T3 +} + +// _Metric3 tracks metrics of triplets of values. +type _Metric3[T1, T2, T3 comparable] struct { + mu sync.Mutex + m map[key3[T1, T2, T3]]int +} + +// Add adds another instance of some triplet of values. +func (m *_Metric3[T1, T2, T3]) Add(v1 T1, v2 T2, v3 T3) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[key3[T1, T2, T3]]int) + } + m.m[key3[T1, T2, T3]{v1, v2, v3}]++ +} + +// Count returns the number of instances we've seen of v1/v2/v3. +func (m *_Metric3[T1, T2, T3]) Count(v1 T1, v2 T2, v3 T3) int { + m.mu.Lock() + defer m.mu.Unlock() + return m.m[key3[T1, T2, T3]{v1, v2, v3}] +} + +// Metrics returns all the values we've seen, in an indeterminate order. +func (m *_Metric3[T1, T2, T3]) Metrics() (r1 []T1, r2 []T2, r3 []T3) { + for k := range m.m { + r1 = append(r1, k.f1) + r2 = append(r2, k.f2) + r3 = append(r3, k.f3) + } + return r1, r2, r3 +} + +type S struct{ a, b, c string } + +func TestMetrics() { + m1 := _Metric1[string]{} + if got := m1.Count("a"); got != 0 { + panic(fmt.Sprintf("Count(%q) = %d, want 0", "a", got)) + } + m1.Add("a") + m1.Add("a") + if got := m1.Count("a"); got != 2 { + panic(fmt.Sprintf("Count(%q) = %d, want 2", "a", got)) + } + if got, want := m1.Metrics(), []string{"a"}; !_SlicesEqual(got, want) { + panic(fmt.Sprintf("Metrics = %v, want %v", got, want)) + } + + m2 := _Metric2[int, float64]{} + m2.Add(1, 1) + m2.Add(2, 2) + m2.Add(3, 3) + m2.Add(3, 3) + k1, k2 := m2.Metrics() + + sort.Ints(k1) + w1 := []int{1, 2, 3} + if !_SlicesEqual(k1, w1) { + panic(fmt.Sprintf("_Metric2.Metrics first slice = %v, want %v", k1, w1)) + } + + sort.Float64s(k2) + w2 := []float64{1, 2, 3} + if !_SlicesEqual(k2, w2) { + panic(fmt.Sprintf("_Metric2.Metrics first slice = %v, want %v", k2, w2)) + } + + m3 := _Metric3[string, S, S]{} + m3.Add("a", S{"d", "e", "f"}, S{"g", "h", "i"}) + m3.Add("a", S{"d", "e", "f"}, S{"g", "h", "i"}) + m3.Add("a", S{"d", "e", "f"}, S{"g", "h", "i"}) + m3.Add("b", S{"d", "e", "f"}, S{"g", "h", "i"}) + if got := m3.Count("a", S{"d", "e", "f"}, S{"g", "h", "i"}); got != 3 { + panic(fmt.Sprintf("Count(%v, %v, %v) = %d, want 3", "a", S{"d", "e", "f"}, S{"g", "h", "i"}, got)) + } +} + +func main() { + TestMetrics() +} + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SlicesEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// _Keys returns the keys of the map m. +// The keys will be an indeterminate order. +func _Keys[K comparable, V any](m map[K]V) []K { + r := make([]K, 0, len(m)) + for k := range m { + r = append(r, k) + } + return r +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/min.go b/platform/dbops/binaries/go/go/test/typeparam/min.go new file mode 100644 index 0000000000000000000000000000000000000000..a9224507dfc2f2a040421602de021143b675c19a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/min.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Ordered interface { + ~int | ~int64 | ~float64 | ~string +} + +func min[T Ordered](x, y T) T { + if x < y { + return x + } + return y +} + +func main() { + const want = 2 + if got := min[int](2, 3); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := min(2, 3); got != want { + panic(fmt.Sprintf("want %d, got %d", want, got)) + } + + if got := min[float64](3.5, 2.0); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := min(3.5, 2.0); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + const want2 = "ay" + if got := min[string]("bb", "ay"); got != want2 { + panic(fmt.Sprintf("got %d, want %d", got, want2)) + } + + if got := min("bb", "ay"); got != want2 { + panic(fmt.Sprintf("got %d, want %d", got, want2)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/mincheck.go b/platform/dbops/binaries/go/go/test/typeparam/mincheck.go new file mode 100644 index 0000000000000000000000000000000000000000..e3a470b4195ab9ee0b49030efa76975b00b284f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/mincheck.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/minimp.go b/platform/dbops/binaries/go/go/test/typeparam/minimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/minimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/mutualimp.go b/platform/dbops/binaries/go/go/test/typeparam/mutualimp.go new file mode 100644 index 0000000000000000000000000000000000000000..b83fbd7af16a576c16e0fc73b84f1ca0f618b756 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/mutualimp.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/nested.go b/platform/dbops/binaries/go/go/test/typeparam/nested.go new file mode 100644 index 0000000000000000000000000000000000000000..cdb8bfb57424fbd24172778c7b02159268a742d6 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/nested.go @@ -0,0 +1,134 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This test case stress tests a number of subtle cases involving +// nested type-parameterized declarations. At a high-level, it +// declares a generic function that contains a generic type +// declaration: +// +// func F[A intish]() { +// type T[B intish] struct{} +// +// // store reflect.Type tuple (A, B, F[A].T[B]) in tests +// } +// +// It then instantiates this function with a variety of type arguments +// for A and B. Particularly tricky things like shadowed types. +// +// From this data it tests two things: +// +// 1. Given tuples (A, B, F[A].T[B]) and (A', B', F[A'].T[B']), +// F[A].T[B] should be identical to F[A'].T[B'] iff (A, B) is +// identical to (A', B'). +// +// 2. A few of the instantiations are constructed to be identical, and +// it tests that exactly these pairs are duplicated (by golden +// output comparison to nested.out). +// +// In both cases, we're effectively using the compiler's existing +// runtime.Type handling (which is well tested) of type identity of A +// and B as a way to help bootstrap testing and validate its new +// runtime.Type handling of F[A].T[B]. +// +// This isn't perfect, but it smoked out a handful of issues in +// gotypes2 and unified IR. + +package main + +import ( + "fmt" + "reflect" +) + +type test struct { + TArgs [2]reflect.Type + Instance reflect.Type +} + +var tests []test + +type intish interface{ ~int } + +type Int int +type GlobalInt = Int // allow access to global Int, even when shadowed + +func F[A intish]() { + add := func(B, T interface{}) { + tests = append(tests, test{ + TArgs: [2]reflect.Type{ + reflect.TypeOf(A(0)), + reflect.TypeOf(B), + }, + Instance: reflect.TypeOf(T), + }) + } + + type Int int + + type T[B intish] struct{} + + add(int(0), T[int]{}) + add(Int(0), T[Int]{}) + add(GlobalInt(0), T[GlobalInt]{}) + add(A(0), T[A]{}) // NOTE: intentionally dups with int and GlobalInt + + type U[_ any] int + type V U[int] + type W V + + add(U[int](0), T[U[int]]{}) + add(U[Int](0), T[U[Int]]{}) + add(U[GlobalInt](0), T[U[GlobalInt]]{}) + add(U[A](0), T[U[A]]{}) // NOTE: intentionally dups with U[int] and U[GlobalInt] + add(V(0), T[V]{}) + add(W(0), T[W]{}) +} + +func main() { + type Int int + + F[int]() + F[Int]() + F[GlobalInt]() + + type U[_ any] int + type V U[int] + type W V + + F[U[int]]() + F[U[Int]]() + F[U[GlobalInt]]() + F[V]() + F[W]() + + type X[A any] U[X[A]] + + F[X[int]]() + F[X[Int]]() + F[X[GlobalInt]]() + + for j, tj := range tests { + for i, ti := range tests[:j+1] { + if (ti.TArgs == tj.TArgs) != (ti.Instance == tj.Instance) { + fmt.Printf("FAIL: %d,%d: %s, but %s\n", i, j, eq(ti.TArgs, tj.TArgs), eq(ti.Instance, tj.Instance)) + } + + // The test is constructed so we should see a few identical types. + // See "NOTE" comments above. + if i != j && ti.Instance == tj.Instance { + fmt.Printf("%d,%d: %v\n", i, j, ti.Instance) + } + } + } +} + +func eq(a, b interface{}) string { + op := "==" + if a != b { + op = "!=" + } + return fmt.Sprintf("%v %s %v", a, op, b) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/nested.out b/platform/dbops/binaries/go/go/test/typeparam/nested.out new file mode 100644 index 0000000000000000000000000000000000000000..0836d9b0dc06421c8927a92edbc7de0772e462b1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/nested.out @@ -0,0 +1,4 @@ +0,3: main.T[int;int] +4,7: main.T[int;main.U[int;int]·3] +22,23: main.T[main.Int;main.Int] +26,27: main.T[main.Int;main.U[main.Int;main.Int]·3] diff --git a/platform/dbops/binaries/go/go/test/typeparam/ordered.go b/platform/dbops/binaries/go/go/test/typeparam/ordered.go new file mode 100644 index 0000000000000000000000000000000000000000..d30429885c151052c3d5b289b48f34daea701f87 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/ordered.go @@ -0,0 +1,95 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "math" + "sort" +) + +type Ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +type orderedSlice[Elem Ordered] []Elem + +func (s orderedSlice[Elem]) Len() int { return len(s) } +func (s orderedSlice[Elem]) Less(i, j int) bool { + if s[i] < s[j] { + return true + } + isNaN := func(f Elem) bool { return f != f } + if isNaN(s[i]) && !isNaN(s[j]) { + return true + } + return false +} +func (s orderedSlice[Elem]) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +func _OrderedSlice[Elem Ordered](s []Elem) { + sort.Sort(orderedSlice[Elem](s)) +} + +var ints = []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586} +var float64s = []float64{74.3, 59.0, math.Inf(1), 238.2, -784.0, 2.3, math.NaN(), math.NaN(), math.Inf(-1), 9845.768, -959.7485, 905, 7.8, 7.8} +var strings = []string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"} + +func TestSortOrderedInts() bool { + return testOrdered("ints", ints, sort.Ints) +} + +func TestSortOrderedFloat64s() bool { + return testOrdered("float64s", float64s, sort.Float64s) +} + +func TestSortOrderedStrings() bool { + return testOrdered("strings", strings, sort.Strings) +} + +func testOrdered[Elem Ordered](name string, s []Elem, sorter func([]Elem)) bool { + s1 := make([]Elem, len(s)) + copy(s1, s) + s2 := make([]Elem, len(s)) + copy(s2, s) + _OrderedSlice(s1) + sorter(s2) + ok := true + if !sliceEq(s1, s2) { + fmt.Printf("%s: got %v, want %v", name, s1, s2) + ok = false + } + for i := len(s1) - 1; i > 0; i-- { + if s1[i] < s1[i-1] { + fmt.Printf("%s: element %d (%v) < element %d (%v)", name, i, s1[i], i-1, s1[i-1]) + ok = false + } + } + return ok +} + +func sliceEq[Elem Ordered](s1, s2 []Elem) bool { + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +func main() { + if !TestSortOrderedInts() || !TestSortOrderedFloat64s() || !TestSortOrderedStrings() { + panic("failure") + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/orderedmap.go b/platform/dbops/binaries/go/go/test/typeparam/orderedmap.go new file mode 100644 index 0000000000000000000000000000000000000000..12456699a5a1eff962a72130257bbd465ff60ac3 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/orderedmap.go @@ -0,0 +1,286 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package orderedmap provides an ordered map, implemented as a binary tree. +package main + +import ( + "bytes" + "context" + "fmt" + "runtime" +) + +type Ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +// _Map is an ordered map. +type _Map[K, V any] struct { + root *node[K, V] + compare func(K, K) int +} + +// node is the type of a node in the binary tree. +type node[K, V any] struct { + key K + val V + left, right *node[K, V] +} + +// _New returns a new map. It takes a comparison function that compares two +// keys and returns < 0 if the first is less, == 0 if they are equal, +// > 0 if the first is greater. +func _New[K, V any](compare func(K, K) int) *_Map[K, V] { + return &_Map[K, V]{compare: compare} +} + +// _NewOrdered returns a new map whose key is an ordered type. +// This is like _New, but does not require providing a compare function. +// The map compare function uses the obvious key ordering. +func _NewOrdered[K Ordered, V any]() *_Map[K, V] { + return _New[K, V](func(k1, k2 K) int { + switch { + case k1 < k2: + return -1 + case k1 == k2: + return 0 + default: + return 1 + } + }) +} + +// find looks up key in the map, returning either a pointer to the slot of the +// node holding key, or a pointer to the slot where should a node would go. +func (m *_Map[K, V]) find(key K) **node[K, V] { + pn := &m.root + for *pn != nil { + switch cmp := m.compare(key, (*pn).key); { + case cmp < 0: + pn = &(*pn).left + case cmp > 0: + pn = &(*pn).right + default: + return pn + } + } + return pn +} + +// Insert inserts a new key/value into the map. +// If the key is already present, the value is replaced. +// Reports whether this is a new key. +func (m *_Map[K, V]) Insert(key K, val V) bool { + pn := m.find(key) + if *pn != nil { + (*pn).val = val + return false + } + *pn = &node[K, V]{key: key, val: val} + return true +} + +// Find returns the value associated with a key, or the zero value +// if not present. The found result reports whether the key was found. +func (m *_Map[K, V]) Find(key K) (V, bool) { + pn := m.find(key) + if *pn == nil { + var zero V + return zero, false + } + return (*pn).val, true +} + +// keyValue is a pair of key and value used while iterating. +type keyValue[K, V any] struct { + key K + val V +} + +// iterate returns an iterator that traverses the map. +func (m *_Map[K, V]) Iterate() *_Iterator[K, V] { + sender, receiver := _Ranger[keyValue[K, V]]() + var f func(*node[K, V]) bool + f = func(n *node[K, V]) bool { + if n == nil { + return true + } + // Stop the traversal if Send fails, which means that + // nothing is listening to the receiver. + return f(n.left) && + sender.Send(context.Background(), keyValue[K, V]{n.key, n.val}) && + f(n.right) + } + go func() { + f(m.root) + sender.Close() + }() + return &_Iterator[K, V]{receiver} +} + +// _Iterator is used to iterate over the map. +type _Iterator[K, V any] struct { + r *_Receiver[keyValue[K, V]] +} + +// Next returns the next key and value pair, and a boolean that reports +// whether they are valid. If not valid, we have reached the end of the map. +func (it *_Iterator[K, V]) Next() (K, V, bool) { + keyval, ok := it.r.Next(context.Background()) + if !ok { + var zerok K + var zerov V + return zerok, zerov, false + } + return keyval.key, keyval.val, true +} + +func TestMap() { + m := _New[[]byte, int](bytes.Compare) + + if _, found := m.Find([]byte("a")); found { + panic(fmt.Sprintf("unexpectedly found %q in empty map", []byte("a"))) + } + if !m.Insert([]byte("a"), 'a') { + panic(fmt.Sprintf("key %q unexpectedly already present", []byte("a"))) + } + if !m.Insert([]byte("c"), 'c') { + panic(fmt.Sprintf("key %q unexpectedly already present", []byte("c"))) + } + if !m.Insert([]byte("b"), 'b') { + panic(fmt.Sprintf("key %q unexpectedly already present", []byte("b"))) + } + if m.Insert([]byte("c"), 'x') { + panic(fmt.Sprintf("key %q unexpectedly not present", []byte("c"))) + } + + if v, found := m.Find([]byte("a")); !found { + panic(fmt.Sprintf("did not find %q", []byte("a"))) + } else if v != 'a' { + panic(fmt.Sprintf("key %q returned wrong value %c, expected %c", []byte("a"), v, 'a')) + } + if v, found := m.Find([]byte("c")); !found { + panic(fmt.Sprintf("did not find %q", []byte("c"))) + } else if v != 'x' { + panic(fmt.Sprintf("key %q returned wrong value %c, expected %c", []byte("c"), v, 'x')) + } + + if _, found := m.Find([]byte("d")); found { + panic(fmt.Sprintf("unexpectedly found %q", []byte("d"))) + } + + gather := func(it *_Iterator[[]byte, int]) []int { + var r []int + for { + _, v, ok := it.Next() + if !ok { + return r + } + r = append(r, v) + } + } + got := gather(m.Iterate()) + want := []int{'a', 'b', 'x'} + if !_SliceEqual(got, want) { + panic(fmt.Sprintf("Iterate returned %v, want %v", got, want)) + } +} + +func main() { + TestMap() +} + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// Ranger returns a Sender and a Receiver. The Receiver provides a +// Next method to retrieve values. The Sender provides a Send method +// to send values and a Close method to stop sending values. The Next +// method indicates when the Sender has been closed, and the Send +// method indicates when the Receiver has been freed. +// +// This is a convenient way to exit a goroutine sending values when +// the receiver stops reading them. +func _Ranger[Elem any]() (*_Sender[Elem], *_Receiver[Elem]) { + c := make(chan Elem) + d := make(chan struct{}) + s := &_Sender[Elem]{ + values: c, + done: d, + } + r := &_Receiver[Elem]{ + values: c, + done: d, + } + runtime.SetFinalizer(r, (*_Receiver[Elem]).finalize) + return s, r +} + +// A _Sender is used to send values to a Receiver. +type _Sender[Elem any] struct { + values chan<- Elem + done <-chan struct{} +} + +// Send sends a value to the receiver. It reports whether the value was sent. +// The value will not be sent if the context is closed or the receiver +// is freed. +func (s *_Sender[Elem]) Send(ctx context.Context, v Elem) bool { + select { + case <-ctx.Done(): + return false + case s.values <- v: + return true + case <-s.done: + return false + } +} + +// Close tells the receiver that no more values will arrive. +// After Close is called, the _Sender may no longer be used. +func (s *_Sender[Elem]) Close() { + close(s.values) +} + +// A _Receiver receives values from a _Sender. +type _Receiver[Elem any] struct { + values <-chan Elem + done chan<- struct{} +} + +// Next returns the next value from the channel. The bool result indicates +// whether the value is valid. +func (r *_Receiver[Elem]) Next(ctx context.Context) (v Elem, ok bool) { + select { + case <-ctx.Done(): + case v, ok = <-r.values: + } + return v, ok +} + +// finalize is a finalizer for the receiver. +func (r *_Receiver[Elem]) finalize() { + close(r.done) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/orderedmapsimp.go b/platform/dbops/binaries/go/go/test/typeparam/orderedmapsimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/orderedmapsimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/pair.go b/platform/dbops/binaries/go/go/test/typeparam/pair.go new file mode 100644 index 0000000000000000000000000000000000000000..dd0adb18400c28c3b2576ff0e6553e6136f3613a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/pair.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "unsafe" +) + +type pair[F1, F2 any] struct { + f1 F1 + f2 F2 +} + +func main() { + p := pair[int32, int64]{1, 2} + if got, want := unsafe.Sizeof(p.f1), uintptr(4); got != want { + panic(fmt.Sprintf("unexpected f1 size == %d, want %d", got, want)) + } + if got, want := unsafe.Sizeof(p.f2), uintptr(8); got != want { + panic(fmt.Sprintf("unexpected f2 size == %d, want %d", got, want)) + } + + type mypair struct { + f1 int32 + f2 int64 + } + mp := mypair(p) + if mp.f1 != 1 || mp.f2 != 2 { + panic(fmt.Sprintf("mp == %#v, want %#v", mp, mypair{1, 2})) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/pairimp.go b/platform/dbops/binaries/go/go/test/typeparam/pairimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/pairimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/pragma.go b/platform/dbops/binaries/go/go/test/typeparam/pragma.go new file mode 100644 index 0000000000000000000000000000000000000000..59411ab6e61446673e4669b8e5b7167b966ff916 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/pragma.go @@ -0,0 +1,19 @@ +// errorcheck -0 -m + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Make sure the go:noinline pragma makes it from a +// generic function to any of its stenciled instances. + +package main + +//go:noinline +func f[T any](x T) T { + return x +} + +func main() { // ERROR "can inline main" + println(f(5)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/recoverimp.go b/platform/dbops/binaries/go/go/test/typeparam/recoverimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/recoverimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/recoverimp.out b/platform/dbops/binaries/go/go/test/typeparam/recoverimp.out new file mode 100644 index 0000000000000000000000000000000000000000..3c8b38cbaeaa7a397e5c1bebcb3084aaf70407ac --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/recoverimp.out @@ -0,0 +1,2 @@ +panic: 5.3 +panic: hello diff --git a/platform/dbops/binaries/go/go/test/typeparam/select.go b/platform/dbops/binaries/go/go/test/typeparam/select.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/select.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/sets.go b/platform/dbops/binaries/go/go/test/typeparam/sets.go new file mode 100644 index 0000000000000000000000000000000000000000..bd08ad7b4b6f9c945a4ef6c88f8bfcc9a4b9aaf1 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/sets.go @@ -0,0 +1,280 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "sort" +) + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// A _Set is a set of elements of some type. +type _Set[Elem comparable] struct { + m map[Elem]struct{} +} + +// _Make makes a new set. +func _Make[Elem comparable]() _Set[Elem] { + return _Set[Elem]{m: make(map[Elem]struct{})} +} + +// Add adds an element to a set. +func (s _Set[Elem]) Add(v Elem) { + s.m[v] = struct{}{} +} + +// Delete removes an element from a set. If the element is not present +// in the set, this does nothing. +func (s _Set[Elem]) Delete(v Elem) { + delete(s.m, v) +} + +// Contains reports whether v is in the set. +func (s _Set[Elem]) Contains(v Elem) bool { + _, ok := s.m[v] + return ok +} + +// Len returns the number of elements in the set. +func (s _Set[Elem]) Len() int { + return len(s.m) +} + +// Values returns the values in the set. +// The values will be in an indeterminate order. +func (s _Set[Elem]) Values() []Elem { + r := make([]Elem, 0, len(s.m)) + for v := range s.m { + r = append(r, v) + } + return r +} + +// _Equal reports whether two sets contain the same elements. +func _Equal[Elem comparable](s1, s2 _Set[Elem]) bool { + if len(s1.m) != len(s2.m) { + return false + } + for v1 := range s1.m { + if !s2.Contains(v1) { + return false + } + } + return true +} + +// Copy returns a copy of s. +func (s _Set[Elem]) Copy() _Set[Elem] { + r := _Set[Elem]{m: make(map[Elem]struct{}, len(s.m))} + for v := range s.m { + r.m[v] = struct{}{} + } + return r +} + +// AddSet adds all the elements of s2 to s. +func (s _Set[Elem]) AddSet(s2 _Set[Elem]) { + for v := range s2.m { + s.m[v] = struct{}{} + } +} + +// SubSet removes all elements in s2 from s. +// Values in s2 that are not in s are ignored. +func (s _Set[Elem]) SubSet(s2 _Set[Elem]) { + for v := range s2.m { + delete(s.m, v) + } +} + +// Intersect removes all elements from s that are not present in s2. +// Values in s2 that are not in s are ignored. +func (s _Set[Elem]) Intersect(s2 _Set[Elem]) { + for v := range s.m { + if !s2.Contains(v) { + delete(s.m, v) + } + } +} + +// Iterate calls f on every element in the set. +func (s _Set[Elem]) Iterate(f func(Elem)) { + for v := range s.m { + f(v) + } +} + +// Filter deletes any elements from s for which f returns false. +func (s _Set[Elem]) Filter(f func(Elem) bool) { + for v := range s.m { + if !f(v) { + delete(s.m, v) + } + } +} + +func TestSet() { + s1 := _Make[int]() + if got := s1.Len(); got != 0 { + panic(fmt.Sprintf("Len of empty set = %d, want 0", got)) + } + s1.Add(1) + s1.Add(1) + s1.Add(1) + if got := s1.Len(); got != 1 { + panic(fmt.Sprintf("(%v).Len() == %d, want 1", s1, got)) + } + s1.Add(2) + s1.Add(3) + s1.Add(4) + if got := s1.Len(); got != 4 { + panic(fmt.Sprintf("(%v).Len() == %d, want 4", s1, got)) + } + if !s1.Contains(1) { + panic(fmt.Sprintf("(%v).Contains(1) == false, want true", s1)) + } + if s1.Contains(5) { + panic(fmt.Sprintf("(%v).Contains(5) == true, want false", s1)) + } + vals := s1.Values() + sort.Ints(vals) + w1 := []int{1, 2, 3, 4} + if !_SliceEqual(vals, w1) { + panic(fmt.Sprintf("(%v).Values() == %v, want %v", s1, vals, w1)) + } +} + +func TestEqual() { + s1 := _Make[string]() + s2 := _Make[string]() + if !_Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s1, s2)) + } + s1.Add("hello") + s1.Add("world") + if got := s1.Len(); got != 2 { + panic(fmt.Sprintf("(%v).Len() == %d, want 2", s1, got)) + } + if _Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", s1, s2)) + } +} + +func TestCopy() { + s1 := _Make[float64]() + s1.Add(0) + s2 := s1.Copy() + if !_Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s1, s2)) + } + s1.Add(1) + if _Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", s1, s2)) + } +} + +func TestAddSet() { + s1 := _Make[int]() + s1.Add(1) + s1.Add(2) + s2 := _Make[int]() + s2.Add(2) + s2.Add(3) + s1.AddSet(s2) + if got := s1.Len(); got != 3 { + panic(fmt.Sprintf("(%v).Len() == %d, want 3", s1, got)) + } + s2.Add(1) + if !_Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s1, s2)) + } +} + +func TestSubSet() { + s1 := _Make[int]() + s1.Add(1) + s1.Add(2) + s2 := _Make[int]() + s2.Add(2) + s2.Add(3) + s1.SubSet(s2) + if got := s1.Len(); got != 1 { + panic(fmt.Sprintf("(%v).Len() == %d, want 1", s1, got)) + } + if vals, want := s1.Values(), []int{1}; !_SliceEqual(vals, want) { + panic(fmt.Sprintf("after SubSet got %v, want %v", vals, want)) + } +} + +func TestIntersect() { + s1 := _Make[int]() + s1.Add(1) + s1.Add(2) + s2 := _Make[int]() + s2.Add(2) + s2.Add(3) + s1.Intersect(s2) + if got := s1.Len(); got != 1 { + panic(fmt.Sprintf("(%v).Len() == %d, want 1", s1, got)) + } + if vals, want := s1.Values(), []int{2}; !_SliceEqual(vals, want) { + panic(fmt.Sprintf("after Intersect got %v, want %v", vals, want)) + } +} + +func TestIterate() { + s1 := _Make[int]() + s1.Add(1) + s1.Add(2) + s1.Add(3) + s1.Add(4) + tot := 0 + s1.Iterate(func(i int) { tot += i }) + if tot != 10 { + panic(fmt.Sprintf("total of %v == %d, want 10", s1, tot)) + } +} + +func TestFilter() { + s1 := _Make[int]() + s1.Add(1) + s1.Add(2) + s1.Add(3) + s1.Filter(func(v int) bool { return v%2 == 0 }) + if vals, want := s1.Values(), []int{2}; !_SliceEqual(vals, want) { + panic(fmt.Sprintf("after Filter got %v, want %v", vals, want)) + } + +} + +func main() { + TestSet() + TestEqual() + TestCopy() + TestAddSet() + TestSubSet() + TestIntersect() + TestIterate() + TestFilter() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/setsimp.go b/platform/dbops/binaries/go/go/test/typeparam/setsimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/setsimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/settable.go b/platform/dbops/binaries/go/go/test/typeparam/settable.go new file mode 100644 index 0000000000000000000000000000000000000000..56cf36745b0369853d3b2be162ec222862d4ff19 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/settable.go @@ -0,0 +1,123 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "strconv" +) + +// Various implementations of fromStrings(). + +type Setter[B any] interface { + Set(string) + *B +} + +// Takes two type parameters where PT = *T +func fromStrings1[T any, PT Setter[T]](s []string) []T { + result := make([]T, len(s)) + for i, v := range s { + // The type of &result[i] is *T which is in the type list + // of Setter, so we can convert it to PT. + p := PT(&result[i]) + // PT has a Set method. + p.Set(v) + } + return result +} + +func fromStrings1a[T any, PT Setter[T]](s []string) []PT { + result := make([]PT, len(s)) + for i, v := range s { + // The type new(T) is *T which is in the type list + // of Setter, so we can convert it to PT. + result[i] = PT(new(T)) + p := result[i] + // PT has a Set method. + p.Set(v) + } + return result +} + +// Takes one type parameter and a set function +func fromStrings2[T any](s []string, set func(*T, string)) []T { + results := make([]T, len(s)) + for i, v := range s { + set(&results[i], v) + } + return results +} + +type Setter2 interface { + Set(string) +} + +// Takes only one type parameter, but causes a panic (see below) +func fromStrings3[T Setter2](s []string) []T { + results := make([]T, len(s)) + for i, v := range s { + // Panics if T is a pointer type because receiver is T(nil). + results[i].Set(v) + } + return results +} + +// Two concrete types with the appropriate Set method. + +type SettableInt int + +func (p *SettableInt) Set(s string) { + i, err := strconv.Atoi(s) + if err != nil { + panic(err) + } + *p = SettableInt(i) +} + +type SettableString struct { + s string +} + +func (x *SettableString) Set(s string) { + x.s = s +} + +func main() { + s := fromStrings1[SettableInt, *SettableInt]([]string{"1"}) + if len(s) != 1 || s[0] != 1 { + panic(fmt.Sprintf("got %v, want %v", s, []int{1})) + } + + s2 := fromStrings1a[SettableInt, *SettableInt]([]string{"1"}) + if len(s2) != 1 || *s2[0] != 1 { + x := 1 + panic(fmt.Sprintf("got %v, want %v", s2, []*int{&x})) + } + + // Test out constraint type inference, which should determine that the second + // type param is *SettableString. + ps := fromStrings1[SettableString]([]string{"x", "y"}) + if len(ps) != 2 || ps[0] != (SettableString{"x"}) || ps[1] != (SettableString{"y"}) { + panic(s) + } + + s = fromStrings2([]string{"1"}, func(p *SettableInt, s string) { p.Set(s) }) + if len(s) != 1 || s[0] != 1 { + panic(fmt.Sprintf("got %v, want %v", s, []int{1})) + } + + defer func() { + if recover() == nil { + panic("did not panic as expected") + } + }() + // This should type check but should panic at run time, + // because it will make a slice of *SettableInt and then call + // Set on a nil value. + fromStrings3[*SettableInt]([]string{"1"}) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/shape1.go b/platform/dbops/binaries/go/go/test/typeparam/shape1.go new file mode 100644 index 0000000000000000000000000000000000000000..2400f1c29a237da314a2bafde30766ff150ea4ba --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/shape1.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + foo() int +} + +// There should be one instantiation of f for both squarer and doubler. +// Similarly, there should be one instantiation of f for both *incrementer and *decrementer. +func f[T I](x T) int { + return x.foo() +} + +type squarer int + +func (x squarer) foo() int { + return int(x*x) +} + +type doubler int + +func (x doubler) foo() int { + return int(2*x) +} + +type incrementer int16 + +func (x *incrementer) foo() int { + return int(*x+1) +} + +type decrementer int32 + +func (x *decrementer) foo() int{ + return int(*x-1) +} + +func main() { + println(f(squarer(5))) + println(f(doubler(5))) + var i incrementer = 5 + println(f(&i)) + var d decrementer = 5 + println(f(&d)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/shape1.out b/platform/dbops/binaries/go/go/test/typeparam/shape1.out new file mode 100644 index 0000000000000000000000000000000000000000..da9a12ded55a5e58b371ee3a4e6c00be8eb0cdc7 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/shape1.out @@ -0,0 +1,4 @@ +25 +10 +6 +4 diff --git a/platform/dbops/binaries/go/go/test/typeparam/sliceimp.go b/platform/dbops/binaries/go/go/test/typeparam/sliceimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/sliceimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/slices.go b/platform/dbops/binaries/go/go/test/typeparam/slices.go new file mode 100644 index 0000000000000000000000000000000000000000..b24817deb0375b217465ba8ad68710e49732f4c5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/slices.go @@ -0,0 +1,318 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package slices provides functions for basic operations on +// slices of any element type. +package main + +import ( + "fmt" + "math" + "strings" +) + +type Ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +type Integer interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr +} + +// Max returns the maximum of two values of some ordered type. +func _Max[T Ordered](a, b T) T { + if a > b { + return a + } + return b +} + +// Min returns the minimum of two values of some ordered type. +func _Min[T Ordered](a, b T) T { + if a < b { + return a + } + return b +} + +// _Equal reports whether two slices are equal: the same length and all +// elements equal. All floating point NaNs are considered equal. +func _Equal[Elem comparable](s1, s2 []Elem) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if v1 != v2 { + isNaN := func(f Elem) bool { return f != f } + if !isNaN(v1) || !isNaN(v2) { + return false + } + } + } + return true +} + +// _EqualFn reports whether two slices are equal using a comparison +// function on each element. +func _EqualFn[Elem any](s1, s2 []Elem, eq func(Elem, Elem) bool) bool { + if len(s1) != len(s2) { + return false + } + for i, v1 := range s1 { + v2 := s2[i] + if !eq(v1, v2) { + return false + } + } + return true +} + +// _Map turns a []Elem1 to a []Elem2 using a mapping function. +func _Map[Elem1, Elem2 any](s []Elem1, f func(Elem1) Elem2) []Elem2 { + r := make([]Elem2, len(s)) + for i, v := range s { + r[i] = f(v) + } + return r +} + +// _Reduce reduces a []Elem1 to a single value of type Elem2 using +// a reduction function. +func _Reduce[Elem1, Elem2 any](s []Elem1, initializer Elem2, f func(Elem2, Elem1) Elem2) Elem2 { + r := initializer + for _, v := range s { + r = f(r, v) + } + return r +} + +// _Filter filters values from a slice using a filter function. +func _Filter[Elem any](s []Elem, f func(Elem) bool) []Elem { + var r []Elem + for _, v := range s { + if f(v) { + r = append(r, v) + } + } + return r +} + +// _Max returns the maximum element in a slice of some ordered type. +// If the slice is empty it returns the zero value of the element type. +func _SliceMax[Elem Ordered](s []Elem) Elem { + if len(s) == 0 { + var zero Elem + return zero + } + return _Reduce(s[1:], s[0], _Max[Elem]) +} + +// _Min returns the minimum element in a slice of some ordered type. +// If the slice is empty it returns the zero value of the element type. +func _SliceMin[Elem Ordered](s []Elem) Elem { + if len(s) == 0 { + var zero Elem + return zero + } + return _Reduce(s[1:], s[0], _Min[Elem]) +} + +// _Append adds values to the end of a slice, returning a new slice. +// This is like the predeclared append function; it's an example +// of how to write it using generics. We used to write code like +// this before append was added to the language, but we had to write +// a separate copy for each type. +func _Append[T any](s []T, t ...T) []T { + lens := len(s) + tot := lens + len(t) + if tot <= cap(s) { + s = s[:tot] + } else { + news := make([]T, tot, tot+tot/2) + _Copy(news, s) + s = news + } + _Copy(s[lens:tot], t) + return s +} + +// _Copy copies values from t to s, stopping when either slice is full, +// returning the number of values copied. This is like the predeclared +// copy function; it's an example of how to write it using generics. +func _Copy[T any](s, t []T) int { + i := 0 + for ; i < len(s) && i < len(t); i++ { + s[i] = t[i] + } + return i +} + +func TestEqual() { + s1 := []int{1, 2, 3} + if !_Equal(s1, s1) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s1, s1)) + } + s2 := []int{1, 2, 3} + if !_Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s1, s2)) + } + s2 = append(s2, 4) + if _Equal(s1, s2) { + panic(fmt.Sprintf("_Equal(%v, %v) = true, want false", s1, s2)) + } + + s3 := []float64{1, 2, math.NaN()} + if !_Equal(s3, s3) { + panic(fmt.Sprintf("_Equal(%v, %v) = false, want true", s3, s3)) + } + + if _Equal(s1, nil) { + panic(fmt.Sprintf("_Equal(%v, nil) = true, want false", s1)) + } + if _Equal(nil, s1) { + panic(fmt.Sprintf("_Equal(nil, %v) = true, want false", s1)) + } + if !_Equal(s1[:0], nil) { + panic(fmt.Sprintf("_Equal(%v, nil = false, want true", s1[:0])) + } +} + +func offByOne[Elem Integer](a, b Elem) bool { + return a == b+1 || a == b-1 +} + +func TestEqualFn() { + s1 := []int{1, 2, 3} + s2 := []int{2, 3, 4} + if _EqualFn(s1, s1, offByOne[int]) { + panic(fmt.Sprintf("_EqualFn(%v, %v, offByOne) = true, want false", s1, s1)) + } + if !_EqualFn(s1, s2, offByOne[int]) { + panic(fmt.Sprintf("_EqualFn(%v, %v, offByOne) = false, want true", s1, s2)) + } + + if !_EqualFn(s1[:0], nil, offByOne[int]) { + panic(fmt.Sprintf("_EqualFn(%v, nil, offByOne) = false, want true", s1[:0])) + } + + s3 := []string{"a", "b", "c"} + s4 := []string{"A", "B", "C"} + if !_EqualFn(s3, s4, strings.EqualFold) { + panic(fmt.Sprintf("_EqualFn(%v, %v, strings.EqualFold) = false, want true", s3, s4)) + } +} + +func TestMap() { + s1 := []int{1, 2, 3} + s2 := _Map(s1, func(i int) float64 { return float64(i) * 2.5 }) + if want := []float64{2.5, 5, 7.5}; !_Equal(s2, want) { + panic(fmt.Sprintf("_Map(%v, ...) = %v, want %v", s1, s2, want)) + } + + s3 := []string{"Hello", "World"} + s4 := _Map(s3, strings.ToLower) + if want := []string{"hello", "world"}; !_Equal(s4, want) { + panic(fmt.Sprintf("_Map(%v, strings.ToLower) = %v, want %v", s3, s4, want)) + } + + s5 := _Map(nil, func(i int) int { return i }) + if len(s5) != 0 { + panic(fmt.Sprintf("_Map(nil, identity) = %v, want empty slice", s5)) + } +} + +func TestReduce() { + s1 := []int{1, 2, 3} + r := _Reduce(s1, 0, func(f float64, i int) float64 { return float64(i)*2.5 + f }) + if want := 15.0; r != want { + panic(fmt.Sprintf("_Reduce(%v, 0, ...) = %v, want %v", s1, r, want)) + } + + if got := _Reduce(nil, 0, func(i, j int) int { return i + j }); got != 0 { + panic(fmt.Sprintf("_Reduce(nil, 0, add) = %v, want 0", got)) + } +} + +func TestFilter() { + s1 := []int{1, 2, 3} + s2 := _Filter(s1, func(i int) bool { return i%2 == 0 }) + if want := []int{2}; !_Equal(s2, want) { + panic(fmt.Sprintf("_Filter(%v, even) = %v, want %v", s1, s2, want)) + } + + if s3 := _Filter(s1[:0], func(i int) bool { return true }); len(s3) > 0 { + panic(fmt.Sprintf("_Filter(%v, identity) = %v, want empty slice", s1[:0], s3)) + } +} + +func TestMax() { + s1 := []int{1, 2, 3, -5} + if got, want := _SliceMax(s1), 3; got != want { + panic(fmt.Sprintf("_Max(%v) = %d, want %d", s1, got, want)) + } + + s2 := []string{"aaa", "a", "aa", "aaaa"} + if got, want := _SliceMax(s2), "aaaa"; got != want { + panic(fmt.Sprintf("_Max(%v) = %q, want %q", s2, got, want)) + } + + if got, want := _SliceMax(s2[:0]), ""; got != want { + panic(fmt.Sprintf("_Max(%v) = %q, want %q", s2[:0], got, want)) + } +} + +func TestMin() { + s1 := []int{1, 2, 3, -5} + if got, want := _SliceMin(s1), -5; got != want { + panic(fmt.Sprintf("_Min(%v) = %d, want %d", s1, got, want)) + } + + s2 := []string{"aaa", "a", "aa", "aaaa"} + if got, want := _SliceMin(s2), "a"; got != want { + panic(fmt.Sprintf("_Min(%v) = %q, want %q", s2, got, want)) + } + + if got, want := _SliceMin(s2[:0]), ""; got != want { + panic(fmt.Sprintf("_Min(%v) = %q, want %q", s2[:0], got, want)) + } +} + +func TestAppend() { + s := []int{1, 2, 3} + s = _Append(s, 4, 5, 6) + want := []int{1, 2, 3, 4, 5, 6} + if !_Equal(s, want) { + panic(fmt.Sprintf("after _Append got %v, want %v", s, want)) + } +} + +func TestCopy() { + s1 := []int{1, 2, 3} + s2 := []int{4, 5} + if got := _Copy(s1, s2); got != 2 { + panic(fmt.Sprintf("_Copy returned %d, want 2", got)) + } + want := []int{4, 5, 3} + if !_Equal(s1, want) { + panic(fmt.Sprintf("after _Copy got %v, want %v", s1, want)) + } +} +func main() { + TestEqual() + TestEqualFn() + TestMap() + TestReduce() + TestFilter() + TestMax() + TestMin() + TestAppend() + TestCopy() +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/smallest.go b/platform/dbops/binaries/go/go/test/typeparam/smallest.go new file mode 100644 index 0000000000000000000000000000000000000000..0ebd10ec3b6d8437b15483098a352039d410df2d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/smallest.go @@ -0,0 +1,42 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type Ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +func Smallest[T Ordered](s []T) T { + r := s[0] // panics if slice is empty + for _, v := range s[1:] { + if v < r { + r = v + } + } + return r +} + +func main() { + vec1 := []float64{5.3, 1.2, 32.8} + vec2 := []string{"abc", "def", "aaa"} + + want1 := 1.2 + if got := Smallest(vec1); got != want1 { + panic(fmt.Sprintf("got %d, want %d", got, want1)) + } + want2 := "aaa" + if got := Smallest(vec2); got != want2 { + panic(fmt.Sprintf("got %d, want %d", got, want2)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/smoketest.go b/platform/dbops/binaries/go/go/test/typeparam/smoketest.go new file mode 100644 index 0000000000000000000000000000000000000000..b720e04d4a85e8174efccbc1cfc096993986817c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/smoketest.go @@ -0,0 +1,56 @@ +// compile + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file checks simple code using type parameters. + +package smoketest + +// type parameters for functions +func f1[P any]() {} +func f2[P1, P2 any, P3 any]() {} +func f3[P interface{}](x P, y T1[int]) {} + +// function instantiations +var _ = f1[int] +var _ = f2[int, string, struct{}] +var _ = f3[bool] + +// type parameters for types +type T1[P any] struct{} +type T2[P1, P2 any, P3 any] struct{} +type T3[P interface{}] interface{} + +// type instantiations +type _ T1[int] +type _ T2[int, string, struct{}] +type _ T3[bool] + +// methods +func (T1[P]) m1() {} +func (T1[_]) m2() {} +func (x T2[P1, P2, P3]) m() {} + +// type lists +type _ interface { + m1() + m2() + int | float32 | string + m3() +} + +// embedded instantiated types +type _ struct { + f1, f2 int + T1[int] + T2[int, string, struct{}] + T3[bool] +} + +type _ interface { + m1() + m2() + T3[bool] +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/stringable.go b/platform/dbops/binaries/go/go/test/typeparam/stringable.go new file mode 100644 index 0000000000000000000000000000000000000000..791b670a9155a99e90653b07b9d5c33e660bb0db --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/stringable.go @@ -0,0 +1,46 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "strconv" + "strings" +) + +type Stringer interface { + String() string +} + +// StringableList is a slice of some type, where the type +// must have a String method. +type StringableList[T Stringer] []T + +func (s StringableList[T]) String() string { + var sb strings.Builder + for i, v := range s { + if i > 0 { + sb.WriteString(", ") + } + sb.WriteString(v.String()) + } + return sb.String() +} + +type myint int + +func (a myint) String() string { + return strconv.Itoa(int(a)) +} + +func main() { + v := StringableList[myint]{myint(1), myint(2)} + + if got, want := v.String(), "1, 2"; got != want { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/stringer.go b/platform/dbops/binaries/go/go/test/typeparam/stringer.go new file mode 100644 index 0000000000000000000000000000000000000000..0892cd881d546bd1fc734f16593784e31a7e3c31 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/stringer.go @@ -0,0 +1,88 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test method calls on type parameters + +package main + +import ( + "fmt" + "reflect" + "strconv" +) + +// Simple constraint +type Stringer interface { + String() string +} + +func stringify[T Stringer](s []T) (ret []string) { + for _, v := range s { + ret = append(ret, v.String()) + } + return ret +} + +type myint int + +func (i myint) String() string { + return strconv.Itoa(int(i)) +} + +// Constraint with an embedded interface, but still only requires String() +type Stringer2 interface { + CanBeStringer2() int + SubStringer2 +} + +type SubStringer2 interface { + CanBeSubStringer2() int + String() string +} + +func stringify2[T Stringer2](s []T) (ret []string) { + for _, v := range s { + ret = append(ret, v.String()) + } + return ret +} + +func (myint) CanBeStringer2() int { + return 0 +} + +func (myint) CanBeSubStringer2() int { + return 0 +} + +// Test use of method values that are not called +func stringify3[T Stringer](s []T) (ret []string) { + for _, v := range s { + f := v.String + ret = append(ret, f()) + } + return ret +} + +func main() { + x := []myint{myint(1), myint(2), myint(3)} + + got := stringify(x) + want := []string{"1", "2", "3"} + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + got = stringify2(x) + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } + + got = stringify3(x) + if !reflect.DeepEqual(got, want) { + panic(fmt.Sprintf("got %s, want %s", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/stringerimp.go b/platform/dbops/binaries/go/go/test/typeparam/stringerimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/stringerimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/struct.go b/platform/dbops/binaries/go/go/test/typeparam/struct.go new file mode 100644 index 0000000000000000000000000000000000000000..2dad9087bc9aeece5eb7a527e6aa805a727acf66 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/struct.go @@ -0,0 +1,49 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +type E[T any] struct { + v T +} + +type S1 struct { + E[int] + v string +} + +type Eint = E[int] +type Ebool = E[bool] + +type S2 struct { + Eint + Ebool + v string +} + +type S3 struct { + *E[int] +} + +func main() { + s1 := S1{Eint{2}, "foo"} + if got, want := s1.E.v, 2; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + s2 := S2{Eint{3}, Ebool{true}, "foo"} + if got, want := s2.Eint.v, 3; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + var s3 S3 + s3.E = &Eint{4} + if got, want := s3.E.v, 4; got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/structinit.go b/platform/dbops/binaries/go/go/test/typeparam/structinit.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/structinit.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/subdict.go b/platform/dbops/binaries/go/go/test/typeparam/subdict.go new file mode 100644 index 0000000000000000000000000000000000000000..463c510484c5714c92f717ac9bbca5bae82a817e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/subdict.go @@ -0,0 +1,43 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test cases where a main dictionary is needed inside a generic function/method, because +// we are calling a method on a fully-instantiated type or a fully-instantiated function. +// (probably not common situations, of course) + +package main + +import ( + "fmt" +) + +type C comparable + +type value[T C] struct { + val T +} + +func (v *value[T]) test(def T) bool { + return (v.val == def) +} + +func (v *value[T]) get(def T) T { + var c value[int] + if c.test(32) { + return def + } else if v.test(def) { + return def + } else { + return v.val + } +} + +func main() { + var s value[string] + if got, want := s.get("ab"), ""; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/sum.go b/platform/dbops/binaries/go/go/test/typeparam/sum.go new file mode 100644 index 0000000000000000000000000000000000000000..25bac181aa9d969ef3f3906cf0788d20c484e31c --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/sum.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" +) + +func Sum[T interface{ int | float64 }](vec []T) T { + var sum T + for _, elt := range vec { + sum = sum + elt + } + return sum +} + +func Abs(f float64) float64 { + if f < 0.0 { + return -f + } + return f +} + +func main() { + vec1 := []int{3, 4} + vec2 := []float64{5.8, 9.6} + got := Sum[int](vec1) + want := vec1[0] + vec1[1] + if got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + got = Sum(vec1) + if want != got { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + fwant := vec2[0] + vec2[1] + fgot := Sum[float64](vec2) + if Abs(fgot-fwant) > 1e-10 { + panic(fmt.Sprintf("got %f, want %f", fgot, fwant)) + } + fgot = Sum(vec2) + if Abs(fgot-fwant) > 1e-10 { + panic(fmt.Sprintf("got %f, want %f", fgot, fwant)) + } +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/tparam1.go b/platform/dbops/binaries/go/go/test/typeparam/tparam1.go new file mode 100644 index 0000000000000000000000000000000000000000..a05f54265b941edd7d87e209f7a69c02738f10fe --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/tparam1.go @@ -0,0 +1,43 @@ +// errorcheck + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Basic type parameter list type-checking (not syntax) errors. + +package tparam1 + +// The predeclared identifier "any" may be used in place of interface{}. +var _ any + +func _(_ any) + +type _[_ any] struct{} + +const N = 10 + +type ( + _ []struct{} // slice + _ [N]struct{} // array + _[T any] struct{} + _[T, T any] struct{} // ERROR "T redeclared" + _[T1, T2 any, T3 any] struct{} +) + +func _[T any]() {} +func _[T, T any]() {} // ERROR "T redeclared" +func _[T1, T2 any](x T1) T2 { panic(0) } + +// Type parameters are visible from opening [ to end of function. +type C interface{} + +func _[T interface{}]() {} +func _[T C]() {} +func _[T struct{}]() {} // ok if #48424 is accepted +func _[T interface{ m() T }]() {} +func _[T1 interface{ m() T2 }, T2 interface{ m() T1 }]() { + var _ T1 +} + +// TODO(gri) expand this diff --git a/platform/dbops/binaries/go/go/test/typeparam/typelist.go b/platform/dbops/binaries/go/go/test/typeparam/typelist.go new file mode 100644 index 0000000000000000000000000000000000000000..7c713212b061be99a94fc8f5577f7ece148bfd49 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typelist.go @@ -0,0 +1,138 @@ +// compile + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file tests type lists & constraints with core types. + +// Note: This test has been adjusted to use the new +// type set notation rather than type lists. + +package p + +// Assignability of an unnamed pointer type to a type parameter that +// has a matching underlying type. +func _[T interface{}, PT interface{ ~*T }](x T) PT { + return &x +} + +// Indexing of generic types containing type parameters in their type list: +func at[T interface{ ~[]E }, E any](x T, i int) E { + return x[i] +} + +// A generic type inside a function acts like a named type. Its underlying +// type is itself, its "operational type" is defined by the type list in +// the tybe bound, if any. +func _[T interface{ ~int }](x T) { + var _ int = int(x) + var _ T = 42 + var _ T = T(myint(42)) +} + +// TODO: put this type declaration back inside the above function when issue 47631 is fixed. +type myint int + +// Indexing a generic type which has a an array as core type. +func _[T interface{ ~[10]int }](x T) { + _ = x[9] // ok +} + +// Dereference of a generic type which has a pointer as core type. +func _[T interface{ ~*int }](p T) int { + return *p +} + +// Channel send and receive on a generic type which has a channel as core type. +func _[T interface{ ~chan int }](ch T) int { + // This would deadlock if executed (but ok for a compile test) + ch <- 0 + return <-ch +} + +// Calling of a generic type which has a function as core type. +func _[T interface{ ~func() }](f T) { + f() + go f() +} + +// Same, but function has a parameter and return value. +func _[T interface{ ~func(string) int }](f T) int { + return f("hello") +} + +// Map access of a generic type which has a map as core type. +func _[V any, T interface{ ~map[string]V }](p T) V { + return p["test"] +} + +// Testing partial and full type inference, including the case where the types can +// be inferred without needing the types of the function arguments. + +// Cannot embed stand-alone type parameters. Disabled for now. +/* +func f0[A any, B interface{type C}, C interface{type D}, D interface{type A}](A, B, C, D) +func f0x() { + f := f0[string] + f("a", "b", "c", "d") + f0("a", "b", "c", "d") +} + +func f1[A any, B interface{type A}](A, B) +func f1x() { + f := f1[int] + f(int(0), int(0)) + f1(int(0), int(0)) + f(0, 0) + f1(0, 0) +} +*/ + +func f2[A any, B interface{ []A }](_ A, _ B) {} +func f2x() { + f := f2[byte] + f(byte(0), []byte{}) + f2(byte(0), []byte{}) + f(0, []byte{}) + // f2(0, []byte{}) - this one doesn't work +} + +// Cannot embed stand-alone type parameters. Disabled for now. +/* +func f3[A any, B interface{type C}, C interface{type *A}](a A, _ B, c C) +func f3x() { + f := f3[int] + var x int + f(x, &x, &x) + f3(x, &x, &x) +} +*/ + +func f4[A any, B interface{ []C }, C interface{ *A }](_ A, _ B, c C) {} +func f4x() { + f := f4[int] + var x int + f(x, []*int{}, &x) + f4(x, []*int{}, &x) +} + +func f5[A interface { + struct { + b B + c C + } +}, B any, C interface{ *B }](x B) A { + panic(0) +} +func f5x() { + x := f5(1.2) + var _ float64 = x.b + var _ float64 = *x.c +} + +func f6[A any, B interface{ ~struct{ f []A } }](B) A { panic(0) } +func f6x() { + x := f6(struct{ f []string }{}) + var _ string = x +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.go new file mode 100644 index 0000000000000000000000000000000000000000..a0468d378fba709d3b4da82b361c9589cb7af22d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.go @@ -0,0 +1,33 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T any](i interface{}) { + switch i.(type) { + case T: + println("T") + case int: + println("int") + case int32, int16: + println("int32/int16") + case struct{ a, b T }: + println("struct{T,T}") + default: + println("other") + } +} +func main() { + f[float64](float64(6)) + f[float64](int(7)) + f[float64](int32(8)) + f[float64](struct{ a, b float64 }{a: 1, b: 2}) + f[float64](int8(9)) + f[int32](int32(7)) + f[int](int32(7)) + f[any](int(10)) + f[interface{ M() }](int(11)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.out new file mode 100644 index 0000000000000000000000000000000000000000..6b8a33c34575374933aa8d3970f9536a18f152ad --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch1.out @@ -0,0 +1,9 @@ +T +int +int32/int16 +struct{T,T} +other +T +int32/int16 +T +int diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.go new file mode 100644 index 0000000000000000000000000000000000000000..286002a830263b8595f7bf16546410fcf28bb22b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.go @@ -0,0 +1,35 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +func f[T any](i interface{}) { + switch x := i.(type) { + case T: + fmt.Println("T", x) + case int: + fmt.Println("int", x) + case int32, int16: + fmt.Println("int32/int16", x) + case struct{ a, b T }: + fmt.Println("struct{T,T}", x.a, x.b) + default: + fmt.Println("other", x) + } +} +func main() { + f[float64](float64(6)) + f[float64](int(7)) + f[float64](int32(8)) + f[float64](struct{ a, b float64 }{a: 1, b: 2}) + f[float64](int8(9)) + f[int32](int32(7)) + f[int](int32(7)) + f[any](int(10)) + f[interface{ M() }](int(11)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.out new file mode 100644 index 0000000000000000000000000000000000000000..6d4df54124c0fcad2059618a9ab0399be82261a5 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch2.out @@ -0,0 +1,9 @@ +T 6 +int 7 +int32/int16 8 +struct{T,T} 1 2 +other 9 +T 7 +int32/int16 7 +T 10 +int 11 diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.go new file mode 100644 index 0000000000000000000000000000000000000000..b84fdd02eaae3793b175bb6b1ee37c88e7133092 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.go @@ -0,0 +1,48 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface{ foo() int } +type J interface { + I + bar() +} + +type myint int + +func (x myint) foo() int { return int(x) } + +type myfloat float64 + +func (x myfloat) foo() int { return int(x) } + +type myint32 int32 + +func (x myint32) foo() int { return int(x) } +func (x myint32) bar() {} + +func f[T I](i I) { + switch x := i.(type) { + case T: + println("T", x.foo()) + case myint: + println("myint", x.foo()) + default: + println("other", x.foo()) + } +} +func main() { + f[myfloat](myint(6)) + f[myfloat](myfloat(7)) + f[myfloat](myint32(8)) + f[myint32](myint32(8)) + f[myint32](myfloat(7)) + f[myint](myint32(9)) + f[I](myint(10)) + f[J](myint(11)) + f[J](myint32(12)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.out new file mode 100644 index 0000000000000000000000000000000000000000..05ed5331973bde1144d27c6948a96f4ece4f65bb --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch3.out @@ -0,0 +1,9 @@ +myint 6 +T 7 +other 8 +T 8 +other 7 +other 9 +T 10 +myint 11 +T 12 diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.go new file mode 100644 index 0000000000000000000000000000000000000000..3fdf5527202ef3c75808e90ab68252b032621a1d --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.go @@ -0,0 +1,46 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface{ foo() int } +type J interface { + I + bar() +} + +type myint int + +func (x myint) foo() int { return int(x) } + +type myfloat float64 + +func (x myfloat) foo() int { return int(x) } + +type myint32 int32 + +func (x myint32) foo() int { return int(x) } +func (x myint32) bar() {} + +func f[T I](i I) { + switch x := i.(type) { + case T, myint32: + println("T/myint32", x.foo()) + default: + println("other", x.foo()) + } +} +func main() { + f[myfloat](myint(6)) + f[myfloat](myfloat(7)) + f[myfloat](myint32(8)) + f[myint32](myint32(9)) + f[myint](myint32(10)) + f[myint](myfloat(42)) + f[I](myint(10)) + f[J](myint(11)) + f[J](myint32(12)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.out new file mode 100644 index 0000000000000000000000000000000000000000..b98f0743c2ea18ed2cae5be0bbbb094ca2453ea4 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch4.out @@ -0,0 +1,9 @@ +other 6 +T/myint32 7 +T/myint32 8 +T/myint32 9 +T/myint32 10 +other 42 +T/myint32 10 +other 11 +T/myint32 12 diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.go new file mode 100644 index 0000000000000000000000000000000000000000..ac52adbdd0709f71c78d598495d8bfddeadce293 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type myint int +func (x myint) foo() int {return int(x)} + +type myfloat float64 +func (x myfloat) foo() float64 {return float64(x) } + +func f[T any](i interface{}) { + switch x := i.(type) { + case interface { foo() T }: + println("fooer", x.foo()) + default: + println("other") + } +} +func main() { + f[int](myint(6)) + f[int](myfloat(7)) + f[float64](myint(8)) + f[float64](myfloat(9)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.out new file mode 100644 index 0000000000000000000000000000000000000000..6b4cb4416f4536f81658050e0a3e9548728cfc09 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch5.out @@ -0,0 +1,4 @@ +fooer 6 +other +other +fooer +9.000000e+000 diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.go new file mode 100644 index 0000000000000000000000000000000000000000..81d4f2082dbee5eb14ecd67320ed39cdc6a2136e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.go @@ -0,0 +1,30 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T any](i interface{}) { + switch i.(type) { + case T: + println("T") + case int: + println("int") + default: + println("other") + } +} + +type myint int +func (myint) foo() { +} + +func main() { + f[interface{}](nil) + f[interface{}](6) + f[interface{foo()}](nil) + f[interface{foo()}](7) + f[interface{foo()}](myint(8)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.out new file mode 100644 index 0000000000000000000000000000000000000000..441add5ec5bed8e4e8919df3602fc16ba9a3f87a --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch6.out @@ -0,0 +1,5 @@ +other +T +other +int +T diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.go b/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.go new file mode 100644 index 0000000000000000000000000000000000000000..067bed713811d8e48a0b05c84fa94bb6c6f1e094 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func f[T any](i interface{foo()}) { + switch i.(type) { + case interface{bar() T}: + println("barT") + case myint: + println("myint") + case myfloat: + println("myfloat") + default: + println("other") + } +} + +type myint int +func (myint) foo() { +} +func (x myint) bar() int { + return int(x) +} + +type myfloat float64 +func (myfloat) foo() { +} + +func main() { + f[int](nil) + f[int](myint(6)) + f[int](myfloat(7)) +} diff --git a/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.out b/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.out new file mode 100644 index 0000000000000000000000000000000000000000..d7fcad4fee14f8788902cc35bdaa2aa3af80ff6e --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/typeswitch7.out @@ -0,0 +1,3 @@ +other +barT +myfloat diff --git a/platform/dbops/binaries/go/go/test/typeparam/valimp.go b/platform/dbops/binaries/go/go/test/typeparam/valimp.go new file mode 100644 index 0000000000000000000000000000000000000000..40df49f83bef07a3f4c5d8fd4000d97484c3f224 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/valimp.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored diff --git a/platform/dbops/binaries/go/go/test/typeparam/value.go b/platform/dbops/binaries/go/go/test/typeparam/value.go new file mode 100644 index 0000000000000000000000000000000000000000..be25dcefb3f8131fd4efd5818d5d79006d4e6d73 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/typeparam/value.go @@ -0,0 +1,75 @@ +// run + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "fmt" + +type value[T any] struct { + val T +} + +func get[T any](v *value[T]) T { + return v.val +} + +func set[T any](v *value[T], val T) { + v.val = val +} + +func (v *value[T]) set(val T) { + v.val = val +} + +func (v *value[T]) get() T { + return v.val +} + +func main() { + var v1 value[int] + set(&v1, 1) + if got, want := get(&v1), 1; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } + + v1.set(2) + if got, want := v1.get(), 2; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } + + v1p := new(value[int]) + set(v1p, 3) + if got, want := get(v1p), 3; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } + + v1p.set(4) + if got, want := v1p.get(), 4; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } + + var v2 value[string] + set(&v2, "a") + if got, want := get(&v2), "a"; got != want { + panic(fmt.Sprintf("get() == %q, want %q", got, want)) + } + + v2.set("b") + if got, want := get(&v2), "b"; got != want { + panic(fmt.Sprintf("get() == %q, want %q", got, want)) + } + + v2p := new(value[string]) + set(v2p, "c") + if got, want := get(v2p), "c"; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } + + v2p.set("d") + if got, want := v2p.get(), "d"; got != want { + panic(fmt.Sprintf("get() == %d, want %d", got, want)) + } +} diff --git a/platform/dbops/binaries/go/go/test/uintptrescapes.dir/a.go b/platform/dbops/binaries/go/go/test/uintptrescapes.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..29c834096894a9a1e7f6f6bbd6afe221d642440b --- /dev/null +++ b/platform/dbops/binaries/go/go/test/uintptrescapes.dir/a.go @@ -0,0 +1,54 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +import ( + "unsafe" +) + +func recurse(i int, s []byte) byte { + s[0] = byte(i) + if i == 0 { + return s[i] + } else { + var a [1024]byte + r := recurse(i-1, a[:]) + return r + a[0] + } +} + +//go:uintptrescapes +func F1(a uintptr) { + var s [16]byte + recurse(4096, s[:]) + *(*int)(unsafe.Pointer(a)) = 42 +} + +//go:uintptrescapes +func F2(a ...uintptr) { + var s [16]byte + recurse(4096, s[:]) + *(*int)(unsafe.Pointer(a[0])) = 42 +} + +type t struct{} + +func GetT() *t { + return &t{} +} + +//go:uintptrescapes +func (*t) M1(a uintptr) { + var s [16]byte + recurse(4096, s[:]) + *(*int)(unsafe.Pointer(a)) = 42 +} + +//go:uintptrescapes +func (*t) M2(a ...uintptr) { + var s [16]byte + recurse(4096, s[:]) + *(*int)(unsafe.Pointer(a[0])) = 42 +} diff --git a/platform/dbops/binaries/go/go/test/uintptrescapes.dir/main.go b/platform/dbops/binaries/go/go/test/uintptrescapes.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..afda6218adb6cbf85f49a69950f9a7c07c55f459 --- /dev/null +++ b/platform/dbops/binaries/go/go/test/uintptrescapes.dir/main.go @@ -0,0 +1,91 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "sync" + "unsafe" + + "./a" +) + +func F1() int { + var buf [1024]int + a.F1(uintptr(unsafe.Pointer(&buf[0]))) + return buf[0] +} + +func F2() int { + var buf [1024]int + a.F2(uintptr(unsafe.Pointer(&buf[0]))) + return buf[0] +} + +var t = a.GetT() + +func M1() int { + var buf [1024]int + t.M1(uintptr(unsafe.Pointer(&buf[0]))) + return buf[0] +} + +func M2() int { + var buf [1024]int + t.M2(uintptr(unsafe.Pointer(&buf[0]))) + return buf[0] +} + +func main() { + // Use different goroutines to force stack growth. + var wg sync.WaitGroup + wg.Add(4) + c := make(chan bool, 4) + + go func() { + defer wg.Done() + b := F1() + if b != 42 { + fmt.Printf("F1: got %d, expected 42\n", b) + c <- false + } + }() + + go func() { + defer wg.Done() + b := F2() + if b != 42 { + fmt.Printf("F2: got %d, expected 42\n", b) + c <- false + } + }() + + go func() { + defer wg.Done() + b := M1() + if b != 42 { + fmt.Printf("M1: got %d, expected 42\n", b) + c <- false + } + }() + + go func() { + defer wg.Done() + b := M2() + if b != 42 { + fmt.Printf("M2: got %d, expected 42\n", b) + c <- false + } + }() + + wg.Wait() + + select { + case <-c: + os.Exit(1) + default: + } +}