mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
dcb5e0392e
Allow full compilation and running of simple programs with generic functions by stenciling on the fly the needed generic functions. Deal with some simple derived types based on type params. Include a few new typeparam tests min.go and add.go which involve fully compiling and running simple generic code. Change-Id: Ifc2a64ecacdbd860faaeee800e2ef49ffef9df5e Reviewed-on: https://go-review.googlesource.com/c/go/+/289630 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
32 lines
513 B
Go
32 lines
513 B
Go
// run -gcflags=-G=3
|
|
|
|
// 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 (
|
|
"fmt"
|
|
)
|
|
|
|
|
|
func min[T interface{ type int }](x, y T) T {
|
|
if x < y {
|
|
return x
|
|
}
|
|
return y
|
|
}
|
|
|
|
func main() {
|
|
want := 2
|
|
got := min[int](2, 3)
|
|
if want != got {
|
|
panic(fmt.Sprintf("Want %d, got %d", want, got))
|
|
}
|
|
|
|
got = min(2, 3)
|
|
if want != got {
|
|
panic(fmt.Sprintf("Want %d, got %d", want, got))
|
|
}
|
|
}
|