Commit 5d5e73b1 authored by Rob Pike's avatar Rob Pike

text/template: type-check chained node as argument

Was just a missing case (literally) in the type checker.

Fixes #8473.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/142460043
parent 892b5074
...@@ -636,6 +636,8 @@ func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) refle ...@@ -636,6 +636,8 @@ func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) refle
return s.validateType(s.evalPipeline(dot, arg), typ) return s.validateType(s.evalPipeline(dot, arg), typ)
case *parse.IdentifierNode: case *parse.IdentifierNode:
return s.evalFunction(dot, arg, arg, nil, zero) return s.evalFunction(dot, arg, arg, nil, zero)
case *parse.ChainNode:
return s.validateType(s.evalChainNode(dot, arg, nil, zero), typ)
} }
switch typ.Kind() { switch typ.Kind() {
case reflect.Bool: case reflect.Bool:
......
...@@ -176,6 +176,12 @@ func (t *T) Method3(v interface{}) string { ...@@ -176,6 +176,12 @@ func (t *T) Method3(v interface{}) string {
return fmt.Sprintf("Method3: %v", v) return fmt.Sprintf("Method3: %v", v)
} }
func (t *T) Copy() *T {
n := new(T)
*n = *t
return n
}
func (t *T) MAdd(a int, b []int) []int { func (t *T) MAdd(a int, b []int) []int {
v := make([]int, len(b)) v := make([]int, len(b))
for i, x := range b { for i, x := range b {
...@@ -519,6 +525,8 @@ var execTests = []execTest{ ...@@ -519,6 +525,8 @@ var execTests = []execTest{
{"bug12xE", "{{printf `%T` 0xEE}}", "int", T{}, true}, {"bug12xE", "{{printf `%T` 0xEE}}", "int", T{}, true},
{"bug12Xe", "{{printf `%T` 0Xef}}", "int", T{}, true}, {"bug12Xe", "{{printf `%T` 0Xef}}", "int", T{}, true},
{"bug12XE", "{{printf `%T` 0XEE}}", "int", T{}, true}, {"bug12XE", "{{printf `%T` 0XEE}}", "int", T{}, true},
// Chained nodes did not work as arguments. Issue 8473.
{"bug13", "{{print (.Copy).I}}", "17", tVal, true},
} }
func zeroArgs() string { func zeroArgs() string {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment