Initial commit: Go 1.23 release state

This commit is contained in:
Vorapol Rinsatitnon
2024-09-21 23:49:08 +10:00
commit 17cd57a668
13231 changed files with 3114330 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
// 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 T[_ any] int
func F() { _ = new(T[int]) }

View File

@@ -0,0 +1,9 @@
// 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 "./a"
func main() { a.F() }

View File

@@ -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

View File

@@ -0,0 +1,7 @@
// 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 I[T any] interface{ M() T }

View File

@@ -0,0 +1,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 main
import "./a"
var m = a.I[int].M
var never bool
func main() {
if never {
m(nil)
}
}

View File

@@ -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

View File

@@ -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[T any] struct {
F T
}
var X = S[int]{}

View File

@@ -0,0 +1,13 @@
// 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 (
"./a"
)
func main() {
_ = a.X
}

View File

@@ -0,0 +1,9 @@
// 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.
// Reported by Cuong Manh Le.
package ignored

View File

@@ -0,0 +1,84 @@
// 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
// Interface which will be used as a regular interface type and as a type bound.
type Mer interface{
M()
}
// Interface that is a superset of Mer.
type Mer2 interface {
M()
String() string
}
func F[T Mer](t T) {
T.M(t)
t.M()
}
type MyMer int
func (MyMer) M() {}
func (MyMer) String() string {
return "aa"
}
// Parameterized interface
type Abs[T any] interface {
Abs() T
}
func G[T Abs[U], U any](t T) {
T.Abs(t)
t.Abs()
}
type MyInt int
func (m MyInt) Abs() MyInt {
if m < 0 {
return -m
}
return m
}
type Abs2 interface {
Abs() MyInt
}
func main() {
mm := MyMer(3)
ms := struct{ Mer }{Mer: mm }
// Testing F with an interface type arg: Mer and Mer2
F[Mer](mm)
F[Mer2](mm)
F[struct{ Mer }](ms)
F[*struct{ Mer }](&ms)
ms2 := struct { MyMer }{MyMer: mm}
ms3 := struct { *MyMer }{MyMer: &mm}
// Testing F with a concrete type arg
F[MyMer](mm)
F[*MyMer](&mm)
F[struct{ MyMer }](ms2)
F[struct{ *MyMer }](ms3)
F[*struct{ MyMer }](&ms2)
F[*struct{ *MyMer }](&ms3)
// Testing G with a concrete type args
mi := MyInt(-3)
G[MyInt,MyInt](mi)
// Interface Abs[MyInt] holding an mi.
intMi := Abs[MyInt](mi)
// First type arg here is Abs[MyInt], an interface type.
G[Abs[MyInt],MyInt](intMi)
}

View File

@@ -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
// Zero returns the zero value of T
func Zero[T any]() (_ T) {
return
}
type AnyInt[X any] int
func (AnyInt[X]) M() {
var have interface{} = Zero[X]()
var want interface{} = Zero[MyInt]()
if have != want {
println("FAIL")
}
}
type I interface{ M() }
type MyInt int
type U = AnyInt[MyInt]
var x = U(0)
var i I = x
func main() {
x.M()
U.M(x)
(*U).M(&x)
i.M()
I.M(x)
}

View File

@@ -0,0 +1,69 @@
// 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.
// Test that generics, promoted methods, and //go:nointerface
// interoperate as expected.
package main
import (
"reflect"
)
func TypeString[T any]() string {
return reflect.TypeOf(new(T)).Elem().String()
}
func Test[T, Bad, Good any]() {
switch interface{}(new(T)).(type) {
case Bad:
println("FAIL:", TypeString[T](), "matched", TypeString[Bad]())
case Good:
// ok
default:
println("FAIL:", TypeString[T](), "did not match", TypeString[Good]())
}
}
func TestE[T any]() { Test[T, interface{ EBad() }, interface{ EGood() }]() }
func TestX[T any]() { Test[T, interface{ XBad() }, interface{ XGood() }]() }
type E struct{}
//go:nointerface
func (E) EBad() {}
func (E) EGood() {}
type X[T any] struct{ E }
//go:nointerface
func (X[T]) XBad() {}
func (X[T]) XGood() {}
type W struct{ X[int] }
func main() {
_ = E.EGood
_ = E.EBad
TestE[E]()
_ = X[int].EGood
_ = X[int].EBad
_ = X[int].XGood
_ = X[int].XBad
TestE[X[int]]()
TestX[X[int]]()
_ = W.EGood
_ = W.EBad
_ = W.XGood
_ = W.XBad
TestE[W]()
TestX[W]()
}

View File

@@ -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 type assertion panics mention the real interface type,
// not their shape type.
package main
import (
"fmt"
"runtime"
"strings"
)
func main() {
// The exact error message isn't important, but it should mention
// `main.T`, not `go.shape.int_0`.
if have := F[T](); !strings.Contains(have, "interface { T() main.T }") {
fmt.Printf("FAIL: unexpected panic message: %q\n", have)
}
}
type T int
func F[T any]() (res string) {
defer func() {
res = recover().(runtime.Error).Error()
}()
_ = interface{ T() T }(nil).(T)
return
}

View File

@@ -0,0 +1,110 @@
// 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 implicit conversions of derived types to interface type
// in range loops work correctly.
package main
import (
"fmt"
"reflect"
)
func main() {
test{"int", "V"}.match(RangeArrayAny[V]())
test{"int", "V"}.match(RangeArrayIface[V]())
test{"V"}.match(RangeChanAny[V]())
test{"V"}.match(RangeChanIface[V]())
test{"K", "V"}.match(RangeMapAny[K, V]())
test{"K", "V"}.match(RangeMapIface[K, V]())
test{"int", "V"}.match(RangeSliceAny[V]())
test{"int", "V"}.match(RangeSliceIface[V]())
}
type test []string
func (t test) match(args ...any) {
if len(t) != len(args) {
fmt.Printf("FAIL: want %v values, have %v\n", len(t), len(args))
return
}
for i, want := range t {
if have := reflect.TypeOf(args[i]).Name(); want != have {
fmt.Printf("FAIL: %v: want type %v, have %v\n", i, want, have)
}
}
}
type iface interface{ M() int }
type K int
type V int
func (K) M() int { return 0 }
func (V) M() int { return 0 }
func RangeArrayAny[V any]() (k, v any) {
for k, v = range [...]V{zero[V]()} {
}
return
}
func RangeArrayIface[V iface]() (k any, v iface) {
for k, v = range [...]V{zero[V]()} {
}
return
}
func RangeChanAny[V any]() (v any) {
for v = range chanOf(zero[V]()) {
}
return
}
func RangeChanIface[V iface]() (v iface) {
for v = range chanOf(zero[V]()) {
}
return
}
func RangeMapAny[K comparable, V any]() (k, v any) {
for k, v = range map[K]V{zero[K](): zero[V]()} {
}
return
}
func RangeMapIface[K interface {
iface
comparable
}, V iface]() (k, v iface) {
for k, v = range map[K]V{zero[K](): zero[V]()} {
}
return
}
func RangeSliceAny[V any]() (k, v any) {
for k, v = range []V{zero[V]()} {
}
return
}
func RangeSliceIface[V iface]() (k any, v iface) {
for k, v = range []V{zero[V]()} {
}
return
}
func chanOf[T any](elems ...T) chan T {
c := make(chan T, len(elems))
for _, elem := range elems {
c <- elem
}
close(c)
return c
}
func zero[T any]() (_ T) { return }

View File

@@ -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.
// Test that implicit conversions to interface type in a select/case
// clause are compiled correctly.
package main
import "fmt"
func main() { f[int]() }
func f[T any]() {
ch := make(chan T)
close(ch)
var i, ok any
select {
case i, ok = <-ch:
}
fmt.Printf("%T %T\n", i, ok)
}

View File

@@ -0,0 +1 @@
int bool

View File

@@ -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 that type parameter methods are handled correctly, even when
// the instantiating type argument has additional methods.
package main
func main() {
F(X(0))
}
type I interface{ B() }
func F[T I](t T) {
CallMethod(t)
MethodExpr[T]()(t)
MethodVal(t)()
}
func CallMethod[T I](t T) { t.B() }
func MethodExpr[T I]() func(T) { return T.B }
func MethodVal[T I](t T) func() { return t.B }
type X int
func (X) A() { panic("FAIL") }
func (X) B() {}
func (X) C() { panic("FAIL") }

View File

@@ -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
type T[A, B, C any] int
func (T[A, B, C]) m(x int) {
if x <= 0 {
return
}
T[B, C, A](0).m(x - 1)
}
func main() {
T[int8, int16, int32](0).m(3)
}

View File

@@ -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.
// Test that method expressions with a derived receiver type and
// promoted methods work correctly.
package main
func main() {
F[int]()
F[string]()
}
func F[X any]() {
call(T[X].M, T[X].N)
}
func call[X any](fns ...func(T[X]) int) {
for want, fn := range fns {
if have := fn(T[X]{}); have != want {
println("FAIL:", have, "!=", want)
}
}
}
type T[X any] struct {
E1
*E2[*X]
}
type E1 struct{}
type E2[_ any] struct{}
func (E1) M() int { return 0 }
func (*E2[_]) N() int { return 1 }

View File

@@ -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.
// Test that devirtualization doesn't introduce spurious type
// assertion failures due to shaped and non-shaped interfaces having
// distinct itabs.
package main
func main() {
F[int]()
}
func F[T any]() {
var i I[T] = X(0)
i.M()
}
type I[T any] interface{ M() }
type X int
func (X) M() {}

View File

@@ -0,0 +1,7 @@
// 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
func F[T interface{ chan int }](c T) {}

View File

@@ -0,0 +1,9 @@
// 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 g() { a.F(make(chan int)) }

View File

@@ -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

View File

@@ -0,0 +1,12 @@
// 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
func F[T any](T) {
Loop:
for {
break Loop
}
}

View File

@@ -0,0 +1,9 @@
// 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.F(0) }

View File

@@ -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

View File

@@ -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 a
type X[T any] int
func (X[T]) F(T) {}
func x() {
X[interface{}](0).F(0)
}

View File

@@ -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 a
type I[T any] interface{ M() T }
var _ = I[int].M

View File

@@ -0,0 +1,9 @@
// 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 I[T any] interface{ M() T }
var X I[int]

View File

@@ -0,0 +1,9 @@
// 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"
var _ = a.X

View File

@@ -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

View File

@@ -0,0 +1,7 @@
// 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
func F[T interface{ comparable }]() {}

View File

@@ -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 init() {
a.F[func()]() // ERROR "does not satisfy comparable"
}

View File

@@ -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

View File

@@ -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 a
func f[V any]() []V { return []V{0: *new(V)} }
func g() { f[int]() }