-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
What steps will reproduce the problem?
1. Compile and run the following program
package main
import (
"bytes"
"fmt"
"math/big"
"text/template"
)
func main() {
n, _ := new(big.Int).SetString("123456789", 10)
display := func(n *big.Int) string { return n.String() }
tpl := template.Must(template.
New("test").
Funcs(template.FuncMap{"display": display}).
Parse(`{{ index $.Values $.Key | display }}`))
type data struct {
Values map[string]*big.Int
Key string
}
values := map[string]*big.Int{"number": n, "hello": nil}
for _, key := range []string{"number", "hello", "world"} {
buf := new(bytes.Buffer)
err := tpl.Execute(buf, data{values, key})
fmt.Printf("%q\n%v\n", buf.String(), err)
}
}
What is the expected output? What do you see instead?
Expected:
"123456789"
<nil>
"<nil>"
<nil>
"<nil>"
<nil>
Got:
"123456789"
<nil>
"<nil>"
<nil>
""
template: test:1: wrong type for value; expected *big.Int; got string
Please use labels and text to provide additional information.