1
0
mirror of https://github.com/golang/go synced 2024-11-26 21:11:57 -07:00

[dev.typeparams] test: update all the typeparam tests to use the new union/tilde syntax

Did a mix of tilde and non-tilde usage. Tilde notation is not quite
fully functional, so no tests are currently trying to distinguish
(fail/not fail) based on tilde usage.

Change-Id: Ib50cec2fc0684f9d9f3561c889fd44c7a7af458c
Reviewed-on: https://go-review.googlesource.com/c/go/+/324572
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Dan Scales 2021-06-02 18:12:14 -07:00
parent 5a008a92e8
commit 370ff5ff96
18 changed files with 55 additions and 55 deletions

View File

@ -12,10 +12,10 @@ import (
) )
type Numeric interface { type Numeric interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
complex64, complex128 ~complex64 | ~complex128
} }
// numericAbs matches numeric types with an Abs method. // numericAbs matches numeric types with an Abs method.
@ -33,14 +33,14 @@ func absDifference[T numericAbs[T]](a, b T) T {
// orderedNumeric matches numeric types that support the < operator. // orderedNumeric matches numeric types that support the < operator.
type orderedNumeric interface { type orderedNumeric interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64 ~float32 | ~float64
} }
// Complex matches the two complex types, which do not have a < operator. // Complex matches the two complex types, which do not have a < operator.
type Complex interface { type Complex interface {
type complex64, complex128 ~complex64 | ~complex128
} }
// orderedAbs is a helper type that defines an Abs method for // orderedAbs is a helper type that defines an Abs method for

View File

@ -11,7 +11,7 @@ import (
) )
type AddType interface { type AddType interface {
type int, int64, string int | int64 | string
} }
// Add can add numbers or strings // Add can add numbers or strings

View File

@ -12,7 +12,7 @@ import (
) )
type Number interface { type Number interface {
type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64 ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
} }
type MySlice []int type MySlice []int

View File

@ -8,7 +8,7 @@ package main
import "fmt" import "fmt"
func fact[T interface { type int, int64, float64 }](n T) T { func fact[T interface { ~int | ~int64 | ~float64 }](n T) T {
if n == 1 { if n == 1 {
return 1 return 1
} }

View File

@ -4,7 +4,7 @@
package a package a
func Fact[T interface { type int, int64, float64 }](n T) T { func Fact[T interface { int | int64 | float64 }](n T) T {
if n == 1 { if n == 1 {
return 1 return 1
} }

View File

@ -11,10 +11,10 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
// _List is a linked list of ordered values of type T. // _List is a linked list of ordered values of type T.
@ -34,9 +34,9 @@ func (l *_List[T]) Largest() T {
} }
type OrderedNum interface { type OrderedNum interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64 ~float32 | ~float64
} }
// _ListNum is a linked _List of ordered numeric values of type T. // _ListNum is a linked _List of ordered numeric values of type T.

View File

@ -5,10 +5,10 @@
package a package a
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
// List is a linked list of ordered values of type T. // List is a linked list of ordered values of type T.
@ -28,9 +28,9 @@ func (l *List[T]) Largest() T {
} }
type OrderedNum interface { type OrderedNum interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64 ~float32 | ~float64
} }
// ListNum is a linked _List of ordered numeric values of type T. // ListNum is a linked _List of ordered numeric values of type T.

View File

@ -11,7 +11,7 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int64, float64, string ~int | ~int64 | ~float64 | ~string
} }
func min[T Ordered](x, y T) T { func min[T Ordered](x, y T) T {

View File

@ -5,7 +5,7 @@
package a package a
type Ordered interface { type Ordered interface {
type int, int64, float64 int | int64 | float64
} }
func Min[T Ordered](x, y T) T { func Min[T Ordered](x, y T) T {

View File

@ -5,7 +5,7 @@
package a package a
type Ordered interface { type Ordered interface {
type int, int64, float64, string ~int | ~int64 | ~float64 | ~string
} }
func Min[T Ordered](x, y T) T { func Min[T Ordered](x, y T) T {

View File

@ -13,10 +13,10 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
type orderedSlice[Elem Ordered] []Elem type orderedSlice[Elem Ordered] []Elem

View File

@ -15,10 +15,10 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
// _Map is an ordered map. // _Map is an ordered map.

View File

@ -5,10 +5,10 @@
package a package a
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
// Max returns the maximum of two values of some ordered type. // Max returns the maximum of two values of some ordered type.

View File

@ -12,8 +12,8 @@ import (
) )
type Integer interface { type Integer interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
} }
func TestEqual() { func TestEqual() {

View File

@ -15,15 +15,15 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
type Integer interface { type Integer interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
} }
// Max returns the maximum of two values of some ordered type. // Max returns the maximum of two values of some ordered type.

View File

@ -11,10 +11,10 @@ import (
) )
type Ordered interface { type Ordered interface {
type int, int8, int16, int32, int64, ~int | ~int8 | ~int16 | ~int32 | ~int64 |
uint, uint8, uint16, uint32, uint64, uintptr, ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
float32, float64, ~float32 | ~float64 |
string ~string
} }
func Smallest[T Ordered](s []T) T { func Smallest[T Ordered](s []T) T {

View File

@ -37,7 +37,7 @@ func (x T2[P1, P2, P3]) m() {}
type _ interface { type _ interface {
m1() m1()
m2() m2()
type int, float32, string int | float32 | string
m3() m3()
} }

View File

@ -10,7 +10,7 @@ import (
"fmt" "fmt"
) )
func Sum[T interface{ type int, float64 }](vec []T) T { func Sum[T interface{ int | float64 }](vec []T) T {
var sum T var sum T
for _, elt := range vec { for _, elt := range vec {
sum = sum + elt sum = sum + elt