]> Cypherpunks repositories - gostls13.git/commit
text/template: reintroduce implicit indirect of interface values in builtin funcs
authorRuss Cox <rsc@golang.org>
Fri, 11 Nov 2016 16:54:18 +0000 (11:54 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 11 Nov 2016 19:46:17 +0000 (19:46 +0000)
commit39e3cbfff623d7941b519f9d35883ef3b74cbcd6
treefa596d8e2da51025a94b545b3a89c9fa4d4e4b9a
parentfabb4115ed311ec4af19f87c2334e38497dbb8d0
text/template: reintroduce implicit indirect of interface values in builtin funcs

CL 31462 made it possible to operate directly on reflect.Values
instead of always forcing a round trip to interface{} and back.
The round trip was losing addressability, which hurt users.

The round trip was also losing "interface-ness", which helped users.
That is, using reflect.ValueOf(v.Interface()) instead of v was doing
an implicit indirect any time v was itself an interface{} value: the result
was the reflect.Value for the underlying concrete value contained in the
interface, not the interface itself.

CL 31462 eliminated some "unnecessary" reflect.Value round trips
in order to preserve addressability, but in doing so it lost this implicit
indirection. This CL adds the indirection back.

It may help to compare the changes in this CL against funcs.go from CL 31462:
https://go-review.googlesource.com/#/c/31462/4/src/text/template/funcs.go

Everywhere CL 31462 changed 'v := reflect.ValueOf(x)' to 'v := x',
this CL changes 'v := x' to 'v := indirectInterface(x)'.

Fixes #17714.

Change-Id: I67cec4eb41fed1d56e1c19f12b0abbd0e59d35a2
Reviewed-on: https://go-review.googlesource.com/33139
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/text/template/exec.go
src/text/template/exec_test.go
src/text/template/funcs.go