[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 int, int8, int16, int32, int64,
uint, uint8, uint16, uint32, uint64, uintptr,
float32, float64,
complex64, complex128
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~complex64 | ~complex128
}
// 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.
type orderedNumeric 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
}
// Complex matches the two complex types, which do not have a < operator.
type Complex interface {
type complex64, complex128
~complex64 | ~complex128
}
// orderedAbs is a helper type that defines an Abs method for

View file

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

View file

@ -12,7 +12,7 @@ import (
)
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

View file

@ -8,7 +8,7 @@ package main
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 {
return 1
}

View file

@ -4,7 +4,7 @@
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 {
return 1
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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