diff options
author | Dan Scales <danscales@google.com> | 2021-05-09 11:38:34 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-05-21 17:03:30 +0000 |
commit | ccbfbb1c3327fffe88dd6b6da550f4a0cd37db6e (patch) | |
tree | e54eac11914c8444e78acaa5e9f941ce9f3bfdc2 /test/typeparam/factimp.dir | |
parent | 243076da64d251853ed7a69ce770e9fa71b5bf0d (diff) | |
download | go-ccbfbb1c3327fffe88dd6b6da550f4a0cd37db6e.tar.gz go-ccbfbb1c3327fffe88dd6b6da550f4a0cd37db6e.zip |
[dev.typeparams] cmd/compile: export OFUNCINST and OSELRECV2 nodes (for generic functions)
Added new test typeparam/factimp.go and changed a bunch of other tests
to test exporting more generic functions and types.
Change-Id: I573d75431cc92482f8f908695cfbc8e84dbb36d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/321749
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/typeparam/factimp.dir')
-rw-r--r-- | test/typeparam/factimp.dir/a.go | 12 | ||||
-rw-r--r-- | test/typeparam/factimp.dir/main.go | 26 |
2 files changed, 38 insertions, 0 deletions
diff --git a/test/typeparam/factimp.dir/a.go b/test/typeparam/factimp.dir/a.go new file mode 100644 index 0000000000..e11575e66e --- /dev/null +++ b/test/typeparam/factimp.dir/a.go @@ -0,0 +1,12 @@ +// 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 a + +func Fact[T interface { type int, int64, float64 }](n T) T { + if n == T(1) { + return T(1) + } + return n * Fact(n - T(1)) +} diff --git a/test/typeparam/factimp.dir/main.go b/test/typeparam/factimp.dir/main.go new file mode 100644 index 0000000000..c2238002ae --- /dev/null +++ b/test/typeparam/factimp.dir/main.go @@ -0,0 +1,26 @@ +// 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 ( + "a" + "fmt" +) + +func main() { + const want = 120 + + if got := a.Fact(5); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := a.Fact[int64](5); got != want { + panic(fmt.Sprintf("got %d, want %d", got, want)) + } + + if got := a.Fact(5.0); got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } +} |