mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
Status: * [x] parsing code with generics * [x] instantiate generics from concrete types * [x] automatic type inference * [x] support of generic recursive types * [x] support of generic methods * [x] support of generic receivers in methods * [x] support of multiple type parameters * [x] support of generic constraints * [x] tests (see _test/gen*.go) Fixes #1363.
15 lines
223 B
Go
15 lines
223 B
Go
package main
|
|
|
|
type Float interface {
|
|
~float32 | ~float64
|
|
}
|
|
|
|
func add[T Float](a, b T) float64 { return float64(a) + float64(b) }
|
|
|
|
func main() {
|
|
println(add(1, 2))
|
|
}
|
|
|
|
// Error:
|
|
// untyped int does not implement main.Float
|