// ERROR comments must start with text `ERROR "rx"` or `ERROR rx` where
// rx is a regular expression that matches the expected error message.
-// Space around "rx" or rx is ignored. Use the form `ERROR HERE "rx"`
-// for error messages that are located immediately after rather than
-// at a token's position.
-var errRx = regexp.MustCompile(`^ *ERROR *(HERE)? *"?([^"]*)"?`)
+// Space around "rx" or rx is ignored.
+var errRx = regexp.MustCompile(`^ *ERROR *"?([^"]*)"?`)
// errMap collects the regular expressions of ERROR comments found
// in files and returns them as a map of error positions to error messages.
var s scanner.Scanner
s.Init(tok, src, nil, scanner.ScanComments)
var prev token.Pos // position of last non-comment, non-semicolon token
- var here token.Pos // position immediately after the token at position prev
scanFile:
for {
if lit[1] == '*' {
lit = lit[:len(lit)-2] // strip trailing */
}
- if s := errRx.FindStringSubmatch(lit[2:]); len(s) == 3 {
- pos := prev
- if s[1] == "HERE" {
- pos = here
- }
- p := fset.Position(pos).String()
- errmap[p] = append(errmap[p], strings.TrimSpace(s[2]))
+ if s := errRx.FindStringSubmatch(lit[2:]); len(s) == 2 {
+ p := fset.Position(prev).String()
+ errmap[p] = append(errmap[p], strings.TrimSpace(s[1]))
}
case token.SEMICOLON:
// ignore automatically inserted semicolon
fallthrough
default:
prev = pos
- var l int // token length
- if tok.IsLiteral() {
- l = len(lit)
- } else {
- l = len(tok.String())
- }
- here = prev + token.Pos(l)
}
}
}
}
func gos() {
- go 1 /* ERROR HERE "must be function call" */
+ go 1; /* ERROR "must be function call" */
go int /* ERROR "go requires function call, not conversion" */ (0)
go gos()
var c chan int
}
func defers() {
- defer 1 /* ERROR HERE "must be function call" */
+ defer 1; /* ERROR "must be function call" */
defer int /* ERROR "defer requires function call, not conversion" */ (0)
defer defers()
var c chan int