]> Cypherpunks repositories - gostls13.git/commit
text/template: improve nil errors in evalField
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 9 Dec 2018 17:35:21 +0000 (17:35 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 26 Feb 2019 17:50:11 +0000 (17:50 +0000)
commit856525ce5c49624fe43d1842a118964d3e38e528
tree5c33fd8a745db2f3ebe636d869a6360abcca2392
parentbe9c534cdef07630606fde23344fc8a5d769a04e
text/template: improve nil errors in evalField

If we're accessing a field on a nil struct pointer, and that field is
present in the type, we should print a "nil pointer evaluating X.Y" error
instead of the broader "can't evaluate field Y in X". The latter error
should still be used for the cases where the field is simply missing.

While at it, remove the isNil checks in the struct and map cases. The
indirect func will only return a true isNil when returning a pointer or
interface reflect.Value, so it's impossible for either of these checks
to be useful.

Finally, extend the test suite to test a handful of these edge cases,
including the one shown in the original issue.

Fixes #29137.

Change-Id: I53408ced8a7b53807a0a8461b6baef1cd01d25ae
Reviewed-on: https://go-review.googlesource.com/c/153341
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/text/template/exec.go
src/text/template/exec_test.go