1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:04:40 -07:00

gofmt -r: match(...) arguments may be nil; add missing guards

Fixes #1446.

R=rsc
CC=golang-dev
https://golang.org/cl/3981043
This commit is contained in:
Robert Griesemer 2011-01-26 19:17:53 -08:00
parent 9ec785af2f
commit 32a7e46488

View File

@ -124,9 +124,9 @@ func match(m map[string]reflect.Value, pattern, val reflect.Value) bool {
// Wildcard matches any expression. If it appears multiple // Wildcard matches any expression. If it appears multiple
// times in the pattern, it must match the same expression // times in the pattern, it must match the same expression
// each time. // each time.
if m != nil && pattern.Type() == identType { if m != nil && pattern != nil && pattern.Type() == identType {
name := pattern.Interface().(*ast.Ident).Name name := pattern.Interface().(*ast.Ident).Name
if isWildcard(name) { if isWildcard(name) && val != nil {
// wildcards only match expressions // wildcards only match expressions
if _, ok := val.Interface().(ast.Expr); ok { if _, ok := val.Interface().(ast.Expr); ok {
if old, ok := m[name]; ok { if old, ok := m[name]; ok {