aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam/fact.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-02-04 17:40:18 -0800
committerRobert Griesemer <gri@golang.org>2021-02-08 22:24:09 +0000
commita360eeb52831c0dfeb38b49eec6881c06176f181 (patch)
tree6083bdfa4f56a171e230f931742a9881ebe2289c /test/typeparam/fact.go
parent0fbde54ea646aa1363fc172610a75e5ba877d4ec (diff)
downloadgo-a360eeb52831c0dfeb38b49eec6881c06176f181.tar.gz
go-a360eeb52831c0dfeb38b49eec6881c06176f181.zip
[dev.typeparams] cmd/compile/internal/types2: conversions to type parameters are not constant
Disabled test/typeparam/fact.go for now as there's an issue with stenciling. Change-Id: Ie328a217de6d7b6695737f08ef5c944bcdaabd39 Reviewed-on: https://go-review.googlesource.com/c/go/+/290471 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'test/typeparam/fact.go')
-rw-r--r--test/typeparam/fact.go40
1 files changed, 21 insertions, 19 deletions
diff --git a/test/typeparam/fact.go b/test/typeparam/fact.go
index e5e0ad4ff3..8ed9bce7d8 100644
--- a/test/typeparam/fact.go
+++ b/test/typeparam/fact.go
@@ -6,30 +6,32 @@
package main
-import (
- "fmt"
-)
+import "fmt"
+// TODO Stenciling doesn't do the right thing for T(1) at the moment.
-func fact[T interface { type float64 }](n T) T {
- if n == T(1) {
- return T(1)
- }
- return n * fact(n - T(1))
+func fact[T interface { type int, int64, float64 }](n T) T {
+ // TODO remove this return in favor of the correct computation below
+ return n
+ // if n == T(1) {
+ // return T(1)
+ // }
+ // return n * fact(n - T(1))
}
func main() {
- got := fact(4.0)
- want := 24.0
- if got != want {
- panic(fmt.Sprintf("Got %f, want %f", got, want))
+ // TODO change this to 120 once we can compile the function body above
+ const want = 5 // 120
+
+ if got := fact(5); got != want {
+ panic(fmt.Sprintf("got %d, want %d", got, want))
}
- // Re-enable when types2 bug is fixed (can't do T(1) with more than one
- // type in the type list).
- //got = fact(5)
- //want = 120
- //if want != got {
- // panic(fmt.Sprintf("Want %d, got %d", want, got))
- //}
+ if got := fact[int64](5); got != want {
+ panic(fmt.Sprintf("got %d, want %d", got, want))
+ }
+
+ if got := fact(5.0); got != want {
+ panic(fmt.Sprintf("got %f, want %f", got, want))
+ }
}