mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
a360eeb528
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>
37 lines
884 B
Go
37 lines
884 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"
|
|
|
|
// 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))
|
|
}
|
|
|
|
func main() {
|
|
// 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))
|
|
}
|
|
|
|
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))
|
|
}
|
|
}
|