aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam/fact.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-06-02 00:03:25 -0700
committerDan Scales <danscales@google.com>2021-06-02 23:10:42 +0000
commit97cb0113a358a24931bc91c956da0cb023f2776c (patch)
tree0baa45bac527ebaecc3b0eee3e1de3ac53b4cca1 /test/typeparam/fact.go
parent6b1cdeaef3099b32d244cef7bb5adc4d7b7628fc (diff)
downloadgo-97cb0113a358a24931bc91c956da0cb023f2776c.tar.gz
go-97cb0113a358a24931bc91c956da0cb023f2776c.zip
[dev.typeparams] cmd/compile: fix export/import of constants with typeparam type
A constant will have a TYPEPARAM type if it appears in a place where it must match that typeparam type (e.g. in a binary operation with a variable of that typeparam type). If so, then we must write out its actual constant kind as well, so its constant val can be read in properly during import. Fixed some export/import tests which were casting some untyped constants to avoid this problem. Change-Id: I285ad8f1c8febbe526769c96e6b27acbd23050f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/324189 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'test/typeparam/fact.go')
-rw-r--r--test/typeparam/fact.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/test/typeparam/fact.go b/test/typeparam/fact.go
index 16b2adf6fb..ea86ae3e02 100644
--- a/test/typeparam/fact.go
+++ b/test/typeparam/fact.go
@@ -9,10 +9,10 @@ package main
import "fmt"
func fact[T interface { type int, int64, float64 }](n T) T {
- if n == T(1) {
- return T(1)
+ if n == 1 {
+ return 1
}
- return n * fact(n - T(1))
+ return n * fact(n - 1)
}
func main() {