var missingVal = reflect.ValueOf(missingValType{})
+var missingValReflectType = reflect.TypeOf(missingValType{})
+
+func isMissing(v reflect.Value) bool {
+ return v.IsValid() && v.Type() == missingValReflectType
+}
+
// at marks the state to be on node n, for error reporting.
func (s *state) at(node parse.Node) {
s.node = node
}
func (s *state) notAFunction(args []parse.Node, final reflect.Value) {
- if len(args) > 1 || final != missingVal {
+ if len(args) > 1 || !isMissing(final) {
s.errorf("can't give argument to non-function %s", args[0])
}
}
if method := ptr.MethodByName(fieldName); method.IsValid() {
return s.evalCall(dot, method, false, node, fieldName, args, final)
}
- hasArgs := len(args) > 1 || final != missingVal
+ hasArgs := len(args) > 1 || !isMissing(final)
// It's not a method; must be a field of a struct or an element of a map.
switch receiver.Kind() {
case reflect.Struct:
}
typ := fun.Type()
numIn := len(args)
- if final != missingVal {
+ if !isMissing(final) {
numIn++
}
numFixed := len(args)
}
}
// Add final value if necessary.
- if final != missingVal {
+ if !isMissing(final) {
t := typ.In(typ.NumIn() - 1)
if typ.IsVariadic() {
if numIn-1 < numFixed {