Skip to content

text/template: incompatible change using parenthesized expression #35974

@ianlancetaylor

Description

@ianlancetaylor

Sample program:

package main

import (
	"log"
	"os"
	"text/template"
)

const source = "{{(len .FileName) gt 0}}\n"

func main() {
	t := template.Must(template.New("x").Parse(source))
	s := struct{ FileName string }{"filename"}
	if err := t.Execute(os.Stdout, &s); err != nil {
		log.Fatal(err)
	}
	s = struct{ FileName string }{""}
	if err := t.Execute(os.Stdout, &s); err != nil {
		log.Fatal(err)
	}
}

Using Go 1.2 through Go 1.13 this prints

8
0

Using tip this fails:

2019/12/04 13:45:36 template: x:1:2: executing "x" at <(len .FileName) gt 0>: can't give argument to non-function len .FileName

This is due to https://golang.org/cl/206124 "text/template: add error check for parenthesized first argument in pipeline", which was written to fix #31810.

Unless this example is somehow incorrect, I think that we need to roll back that CL and try again for Go 1.15.

CC @robpike

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions