Kaynağa Gözat

Add nil logic for nil Identifier struct

Golang is weird and allows you to call methods on a typed nil.

Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Michael Dresser 2 yıl önce
ebeveyn
işleme
ebc4387ef7
1 değiştirilmiş dosya ile 4 ekleme ve 1 silme
  1. 4 1
      pkg/filter21/ast/tree.go

+ 4 - 1
pkg/filter21/ast/tree.go

@@ -30,9 +30,12 @@ func (id *Identifier) Equal(ident Identifier) bool {
 
 // String returns the string representation for the Identifier
 func (id *Identifier) String() string {
-	if id.Field == nil {
+	if id == nil {
 		return "<nil>"
 	}
+	if id.Field == nil {
+		return "<nil field>"
+	}
 	s := id.Field.Name
 	if id.Key != "" {
 		s += "[" + id.Key + "]"