Skip to content

Commit 60e104c

Browse files
committed
pattern: guard against matching Nil against non-nillable type
1 parent d754133 commit 60e104c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pattern/match.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,16 @@ func (tok Token) Match(m *Matcher, node interface{}) (interface{}, bool) {
505505
}
506506

507507
func (Nil) Match(m *Matcher, node interface{}) (interface{}, bool) {
508-
return nil, isNil(node) || reflect.ValueOf(node).IsNil()
508+
if isNil(node) {
509+
return nil, true
510+
}
511+
v := reflect.ValueOf(node)
512+
switch v.Kind() {
513+
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
514+
return nil, v.IsNil()
515+
default:
516+
return nil, false
517+
}
509518
}
510519

511520
func (builtin Builtin) Match(m *Matcher, node interface{}) (interface{}, bool) {

0 commit comments

Comments
 (0)