// validateType guarantees that the value is valid and assignable to the type.
func (s *state) validateType(value reflect.Value, typ reflect.Type) reflect.Value {
if !value.IsValid() {
- if typ == nil || canBeNil(typ) {
+ if typ == nil {
// An untyped nil interface{}. Accept as a proper nil value.
+ return reflect.ValueOf(nil)
+ }
+ if canBeNil(typ) {
+ // Like above, but use the zero value of the non-nil type.
return reflect.Zero(typ)
}
s.errorf("invalid value; expected %s", typ)
{"empty with struct", "{{.Empty4}}", "{UinEmpty}", tVal, true},
{"empty with struct, field", "{{.Empty4.V}}", "UinEmpty", tVal, true},
+ // Edge cases with <no value> with an interface value
+ {"field on interface", "{{.foo}}", "<no value>", nil, true},
+ {"field on parenthesized interface", "{{(.).foo}}", "<no value>", nil, true},
+
// Method calls.
{".Method0", "-{{.Method0}}-", "-M0-", tVal, true},
{".Method1(1234)", "-{{.Method1 1234}}-", "-1234-", tVal, true},