Skip to content

text/template: interprets nil interface{} as a map #15356

@walken-google

Description

@walken-google

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    1.6.1
  2. What operating system and processor architecture are you using (go env)?
    linux amd64
  3. What did you do?
    http://play.golang.org/p/Fk7G5f3z1q
    The second template takes nil as its data, and accesses its .X field.
  4. What did you expect to see?
    I would expect the second template to return an error, just like the first:
    template: :1:2: executing "" at <.X>: can't evaluate field X in type int
  5. What did you see instead?
    The second template writes out "" and returns no error.
    This seems to correspond to the missingkey=default behaviour, which is documented to happen for maps. I don't think the empty interface should count as a map though, so I would have expected an error instead.

I can volunteer to provide a fix if the current behaviour is recognized to be a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions