Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template:fix line number is wrong in error info #69532

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/text/template/parse/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func lexComment(l *lexer) stateFn {
if !delim {
return l.errorf("comment ends before closing delimiter")
}
l.line += strings.Count(l.input[l.start:l.pos], "\n")
i := l.thisItem(itemComment)
if trimSpace {
l.pos += trimMarkerLen
Expand Down
10 changes: 10 additions & 0 deletions src/text/template/parse/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,16 @@ var lexPosTests = []lexTest{
{itemRightDelim, 11, "}}", 2},
{itemEOF, 13, "", 2},
}},
{"correctline", "{{/*\n*/}}\n{{undefinedFunction \"test\"}}", []item{
{itemComment, 2, "/*\n*/", 1},
{itemText, 9, "\n", 2},
{itemLeftDelim, 10, "{{", 3},
{itemIdentifier, 12, "undefinedFunction", 3},
{itemSpace, 29, " ", 3},
{itemString, 30, "\"test\"", 3},
{itemRightDelim, 36, "}}", 3},
{itemEOF, 38, "", 3},
}},
}

// The other tests don't check position, to make the test cases easier to construct.
Expand Down