Skip to content

Commit

Permalink
text/template/parse: rename DeferFuncCheck to SkipFuncCheck
Browse files Browse the repository at this point in the history
The proposal as accepted in #34652 named the bit SkipFuncCheck.
It was renamed to DeferFuncCheck during the code review on a suggestion by Rob,
along with a comment to “defer type checking functions until template is executed,”
but this description is not accurate: the package has never type-checked functions,
only verified their existence. And the effect of the bit in this package is to eliminate
this check entirely, not to defer it to some later time.

I was writing code using this new bit and was very confused about when the
"type checking" was being deferred to and how to stop that entirely,
since in my use case I wanted no checks at all. What I wanted is what the bit does,
it just wasn't named accurately.

Rename back to SkipFuncCheck.

Change-Id: I8e62099c8a904ed04521eb5b86155290f6d5b12f
Reviewed-on: https://go-review.googlesource.com/c/go/+/317269
Trust: Russ Cox <[email protected]>
Trust: Daniel Martí <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Rob Pike <[email protected]>
  • Loading branch information
rsc committed May 6, 2021
1 parent ba0f8ce commit 0e7a7a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ pkg syscall (windows-amd64), type SysProcAttr struct, AdditionalInheritedHandles
pkg syscall (windows-amd64), type SysProcAttr struct, ParentProcess Handle
pkg testing, method (*B) Setenv(string, string)
pkg testing, method (*T) Setenv(string, string)
pkg text/template/parse, const DeferFuncCheck = 2
pkg text/template/parse, const DeferFuncCheck Mode
pkg text/template/parse, const SkipFuncCheck = 2
pkg text/template/parse, const SkipFuncCheck Mode
pkg time, func UnixMicro(int64) Time
pkg time, func UnixMilli(int64) Time
pkg time, method (*Time) IsDST() bool
Expand Down
6 changes: 3 additions & 3 deletions src/text/template/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Tree struct {
type Mode uint

const (
ParseComments Mode = 1 << iota // parse comments and add them to AST
DeferFuncCheck // defer type checking functions until template is executed
ParseComments Mode = 1 << iota // parse comments and add them to AST
SkipFuncCheck // do not check that functions are defined
)

// Copy returns a copy of the Tree. Any parsing state is discarded.
Expand Down Expand Up @@ -690,7 +690,7 @@ func (t *Tree) operand() Node {
func (t *Tree) term() Node {
switch token := t.nextNonSpace(); token.typ {
case itemIdentifier:
checkFunc := t.Mode&DeferFuncCheck == 0
checkFunc := t.Mode&SkipFuncCheck == 0
if checkFunc && !t.hasFunction(token.val) {
t.errorf("function %q not defined", token.val)
}
Expand Down
6 changes: 3 additions & 3 deletions src/text/template/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ func TestParseWithComments(t *testing.T) {
}
}

func TestDeferFuncCheck(t *testing.T) {
func TestSkipFuncCheck(t *testing.T) {
oldTextFormat := textFormat
textFormat = "%q"
defer func() { textFormat = oldTextFormat }()
tr := New("defer func check")
tr.Mode = DeferFuncCheck
tr := New("skip func check")
tr.Mode = SkipFuncCheck
tmpl, err := tr.Parse("{{fn 1 2}}", "", "", make(map[string]*Tree))
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down

0 comments on commit 0e7a7a6

Please sign in to comment.