mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
When a nil are used in a func composite literal, the nil type is a `func` not a `*node`. This handles this case. Fixes #1249
33 lines
372 B
Go
33 lines
372 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type fn func(string, string) bool
|
|
|
|
var funcs = []fn{
|
|
cmpLessFn,
|
|
cmpGreaterFn,
|
|
nil,
|
|
}
|
|
|
|
func cmpLessFn(a string, b string) bool {
|
|
return a < b
|
|
}
|
|
|
|
func cmpGreaterFn(a string, b string) bool {
|
|
return a > b
|
|
}
|
|
|
|
func main() {
|
|
for _, f := range funcs {
|
|
if f == nil {
|
|
continue
|
|
}
|
|
fmt.Println(f("a", "b"))
|
|
}
|
|
}
|
|
|
|
// Output:
|
|
// true
|
|
// false
|