mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] go/types: convert testdata/examples tests to type set sytax
This is a straightforward port of CL 324529 to go/types. Change-Id: I788b1ac3d4e40060038a134c525c81624add8e81 Reviewed-on: https://go-review.googlesource.com/c/go/+/326680 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
8e14a9cf04
commit
795f4475e5
3 changed files with 8 additions and 8 deletions
2
src/go/types/testdata/examples/functions.go2
vendored
2
src/go/types/testdata/examples/functions.go2
vendored
|
|
@ -98,7 +98,7 @@ func g2b[P, Q any](x P, y Q) {
|
||||||
// Here's an example of a recursive function call with variadic
|
// Here's an example of a recursive function call with variadic
|
||||||
// arguments and type inference inferring the type parameter of
|
// arguments and type inference inferring the type parameter of
|
||||||
// the caller (i.e., itself).
|
// the caller (i.e., itself).
|
||||||
func max[T interface{ type int }](x ...T) T {
|
func max[T interface{ ~int }](x ...T) T {
|
||||||
var x0 T
|
var x0 T
|
||||||
if len(x) > 0 {
|
if len(x) > 0 {
|
||||||
x0 = x[0]
|
x0 = x[0]
|
||||||
|
|
|
||||||
6
src/go/types/testdata/examples/inference.go2
vendored
6
src/go/types/testdata/examples/inference.go2
vendored
|
|
@ -7,7 +7,7 @@
|
||||||
package p
|
package p
|
||||||
|
|
||||||
type Ordered interface {
|
type Ordered interface {
|
||||||
type int, float64, string
|
~int|~float64|~string
|
||||||
}
|
}
|
||||||
|
|
||||||
func min[T Ordered](x, y T) T
|
func min[T Ordered](x, y T) T
|
||||||
|
|
@ -54,7 +54,7 @@ func _() {
|
||||||
mixed[int, string](1.1 /* ERROR cannot use 1.1 */ , "", false)
|
mixed[int, string](1.1 /* ERROR cannot use 1.1 */ , "", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func related1[Slice interface{type []Elem}, Elem any](s Slice, e Elem)
|
func related1[Slice interface{~[]Elem}, Elem any](s Slice, e Elem)
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
// related1 can be called with explicit instantiation.
|
// related1 can be called with explicit instantiation.
|
||||||
|
|
@ -78,7 +78,7 @@ func _() {
|
||||||
related1(si, "foo" /* ERROR cannot use "foo" */ )
|
related1(si, "foo" /* ERROR cannot use "foo" */ )
|
||||||
}
|
}
|
||||||
|
|
||||||
func related2[Elem any, Slice interface{type []Elem}](e Elem, s Slice)
|
func related2[Elem any, Slice interface{~[]Elem}](e Elem, s Slice)
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
// related2 can be called with explicit instantiation.
|
// related2 can be called with explicit instantiation.
|
||||||
|
|
|
||||||
8
src/go/types/testdata/examples/types.go2
vendored
8
src/go/types/testdata/examples/types.go2
vendored
|
|
@ -165,7 +165,7 @@ type _ struct {
|
||||||
// are type parameters. As with ordinary type definitions, the
|
// are type parameters. As with ordinary type definitions, the
|
||||||
// types underlying properties are "inherited" but the methods
|
// types underlying properties are "inherited" but the methods
|
||||||
// are not.
|
// are not.
|
||||||
func _[T interface{ m(); type int }]() {
|
func _[T interface{ m(); ~int }]() {
|
||||||
type L T
|
type L T
|
||||||
var x L
|
var x L
|
||||||
|
|
||||||
|
|
@ -238,11 +238,11 @@ func _[A Adder[A], B Adder[B], C Adder[A]]() {
|
||||||
// The type of variables (incl. parameters and return values) cannot
|
// The type of variables (incl. parameters and return values) cannot
|
||||||
// be an interface with type constraints or be/embed comparable.
|
// be an interface with type constraints or be/embed comparable.
|
||||||
type I interface {
|
type I interface {
|
||||||
type int
|
~int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ interface /* ERROR contains type constraints */ {type int}
|
_ interface /* ERROR contains type constraints */ {~int}
|
||||||
_ I /* ERROR contains type constraints */
|
_ I /* ERROR contains type constraints */
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -273,7 +273,7 @@ func _() {
|
||||||
// (If a type list contains just a single const type, we could
|
// (If a type list contains just a single const type, we could
|
||||||
// allow it, but such type lists don't make much sense in the
|
// allow it, but such type lists don't make much sense in the
|
||||||
// first place.)
|
// first place.)
|
||||||
func _[T interface { type int, float64 }]() {
|
func _[T interface {~int|~float64}]() {
|
||||||
// not valid
|
// not valid
|
||||||
const _ = T /* ERROR not constant */ (0)
|
const _ = T /* ERROR not constant */ (0)
|
||||||
const _ T /* ERROR invalid constant type T */ = 1
|
const _ T /* ERROR invalid constant type T */ = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue