Skip to content

text/template: Boolean operation on boolean pointer in a Template does not yield the correct value #12995

@jmcauley

Description

@jmcauley

If you have a boolean variable and a pointer to a boolean variable in a template, the behavior of the dereferenced values in the template vary incorrectly.

Playground example: https://play.golang.org/p/q7BZFIui5M

Tested with Go versions 1.3.3, 1.4, and 1.5
Tested on Fedora and Mac OS X

Setup:
type Testvalues struct {
Mybool bool
Ptrbool *bool
}
flag := false
testitem = Testvalues{flag, &flag}

Based on this, I would expect {{.Mybool}} {{not .Mybool}} {{.Ptrbool}} {{not .Ptrbool}} to yield: false true false true
Actual results: false true false false

The pointer to the boolean seems to be dereferenced correctly but the logical not operator applied to it does not yield the correct result.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions