aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam/fact.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-02-09 15:13:19 -0800
committerDan Scales <danscales@google.com>2021-02-10 03:33:05 +0000
commitfdf3496fccfd5c5593ac9e03804ffc8feeb59dbc (patch)
treebbe6ab26a31903dcb678a5aff466ca31b2238d8f /test/typeparam/fact.go
parent12e15d430d408ff9a961bdfb72cfc7f0b521a354 (diff)
downloadgo-fdf3496fccfd5c5593ac9e03804ffc8feeb59dbc.tar.gz
go-fdf3496fccfd5c5593ac9e03804ffc8feeb59dbc.zip
[dev.typeparams] cmd/compile: make type conversions by type parameters work
When doing a type conversion using a type param, delay the transformation to OCONV/OCONVNOP until stenciling, since the nodes created depend on the actual type. Re-enable the fact.go test. Change-Id: I3d5861aab3dd0e781d767f67435afaf951dfe451 Reviewed-on: https://go-review.googlesource.com/c/go/+/290752 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'test/typeparam/fact.go')
-rw-r--r--test/typeparam/fact.go15
1 files changed, 5 insertions, 10 deletions
diff --git a/test/typeparam/fact.go b/test/typeparam/fact.go
index 8ed9bce7d8..16b2adf6fb 100644
--- a/test/typeparam/fact.go
+++ b/test/typeparam/fact.go
@@ -8,20 +8,15 @@ package main
import "fmt"
-// TODO Stenciling doesn't do the right thing for T(1) at the moment.
-
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))
+ if n == T(1) {
+ return T(1)
+ }
+ return n * fact(n - T(1))
}
func main() {
- // TODO change this to 120 once we can compile the function body above
- const want = 5 // 120
+ const want = 120
if got := fact(5); got != want {
panic(fmt.Sprintf("got %d, want %d", got, want))