mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
f4722d8449
This test case is failing on the noopt builder, because it disables inlining. Evidently the explicit -gcflags flag in all of our generics tests was overriding the noopt builder's default mode. This CL restores a noop -gcflags to get the builder green again until the issue can be properly fixed. Updates #51413. Change-Id: I61d22a007105f756104ba690b73f1d68ce4be281 Reviewed-on: https://go-review.googlesource.com/c/go/+/388894 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
85 lines
1.4 KiB
Go
85 lines
1.4 KiB
Go
// run -gcflags=""
|
|
|
|
// Copyright 2021 The Go Authors. All 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)
|
|
}
|