Skip to content

text/template, html/template: nil argument to function yields wrong number of args error #18716

@sethvargo

Description

@sethvargo

What version of Go are you using (go version)?

go version go1.7.4 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sethvargo/Development/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.4_2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.4_2/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/g1brm3hj0431461p8cxqtjth0000gn/T/go-build267389745=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

https://play.golang.org/p/R3CMVl_nmx

What did you expect to see?

Passing a nested field in a struct that is nil should pass in the zero value for the accepting function. I either expected a different error, or I expected text/template to coerce the value into the signature of the receiving function (string in this case), and use the string zero value.

What did you see instead?

An error is returned indicating an incorrect number of arguments was provided. This is especially confusing because, even if the zero value is provided, the result of the function call should be nil. At worst you're passing nil to a function that accepts a string, but that's not "incorrect number of args", it's a TypeError.

Related Code

From my tracing, the code appears to be here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions