go/test/typeparam/min.go
Dan Scales dcb5e0392e [dev.typeparams] cmd/compile: add stenciling of simple generic functions
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>
2021-02-05 16:40:12 +00:00

33 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))
}
}