s.errorf("can't call method/function %q with %d results", name, typ.NumOut())
}
+ unwrap := func(v reflect.Value) reflect.Value {
+ if v.Type() == reflectValueType {
+ v = v.Interface().(reflect.Value)
+ }
+ return v
+ }
+
// Special case for builtin and/or, which short-circuit.
if isBuiltin && (name == "and" || name == "or") {
argType := typ.In(0)
for _, arg := range args {
v = s.evalArg(dot, argType, arg).Interface().(reflect.Value)
if truth(v) == (name == "or") {
- return v
+ return unwrap(v)
}
}
if final != missingVal {
v = s.validateType(final, argType)
}
- return v
+ return unwrap(v)
}
// Build the arg list.
s.at(node)
s.errorf("error calling %s: %w", name, err)
}
- if v.Type() == reflectValueType {
- v = v.Interface().(reflect.Value)
- }
- return v
+ return unwrap(v)
}
// canBeNil reports whether an untyped nil can be assigned to the type. See reflect.Zero.
{"or pipe-false", "{{0 | or 0}}", "0", nil, true},
{"boolean if", "{{if and true 1 `hi`}}TRUE{{else}}FALSE{{end}}", "TRUE", tVal, true},
{"boolean if not", "{{if and true 1 `hi` | not}}TRUE{{else}}FALSE{{end}}", "FALSE", nil, true},
+ {"boolean if pipe", "{{if true | not | and 1}}TRUE{{else}}FALSE{{end}}", "FALSE", nil, true},
// Indexing.
{"slice[0]", "{{index .SI 0}}", "3", tVal, true},