1
0
mirror of https://github.com/golang/go synced 2024-11-16 22:54:47 -07:00

go/types: remove support for "ERROR HERE" error markers in tests

There are only two tests that rely on the "ERROR HERE" markers;
yet those tests are trivialy adjustable (by adding an explicit
semicolon) such that they can just use the "ERROR" markers.

For #54511.

Change-Id: Idbb96ca8d35ae2584d195a4ac7c92640b8b492c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/425674
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-08-25 13:48:42 -07:00 committed by Gopher Robot
parent 04eb35998a
commit 73a55c1704
2 changed files with 7 additions and 21 deletions

View File

@ -88,10 +88,8 @@ func parseFiles(t *testing.T, filenames []string, srcs [][]byte, mode parser.Mod
// 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.
@ -108,7 +106,6 @@ func errMap(t *testing.T, files []*ast.File, srcs [][]byte) map[string][]string
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 {
@ -120,13 +117,9 @@ func errMap(t *testing.T, files []*ast.File, srcs [][]byte) map[string][]string
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
@ -136,13 +129,6 @@ func errMap(t *testing.T, files []*ast.File, srcs [][]byte) map[string][]string
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)
}
}
}

View File

@ -229,7 +229,7 @@ func selects() {
}
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
@ -238,7 +238,7 @@ func gos() {
}
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