Skip to content

Commit 40886a0

Browse files
griesemereric
authored andcommitted
internal/types: consistently use double quotes around ERROR patterns
Before matching the pattern, the double quotes are simply stripped (no Go string unquoting) for now. This is a first step towards use of proper Go strings as ERROR patterns. The changes were obtained through a couple of global regexp find/replace commands: /\* ERROR ([^"]+) \*/ => /* ERROR "$1" */ // ERROR ([^"]+)$ => // ERROR "$1" followed up by manual fixes where multiple "/* ERROR"-style errors appeared on the same line (in that case, the first regexp matches the first and last ERROR). For golang#51006. Change-Id: Ib92c2d5e339075aeec1ea74c339b5fecf953d1a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/455718 Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 4944b31 commit 40886a0

File tree

183 files changed

+1490
-1478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+1490
-1478
lines changed

src/cmd/compile/internal/types2/check_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
203203
index := -1 // errList index of matching message, if any
204204
for i, want := range errList {
205205
pattern := strings.TrimSpace(want.Msg[len(" ERROR "):])
206+
// We expect all patterns to be quoted in double quotes
207+
// and then we remove the quotes.
208+
// TODO(gri) use correct strconv.Unquote eventually
206209
if n := len(pattern); n >= 2 && pattern[0] == '"' && pattern[n-1] == '"' {
207210
pattern = pattern[1 : n-1]
211+
} else {
212+
t.Errorf("%s:%d:%d: unquoted pattern: %s", filename, line, want.Pos.Col(), pattern)
213+
continue
208214
}
209215
rx, err := regexp.Compile(pattern)
210216
if err != nil {
@@ -302,7 +308,7 @@ func TestCheck(t *testing.T) {
302308
}
303309
func TestSpec(t *testing.T) { testDirFiles(t, "../../../../internal/types/testdata/spec", 0, false) }
304310
func TestExamples(t *testing.T) {
305-
testDirFiles(t, "../../../../internal/types/testdata/examples", 45, false)
311+
testDirFiles(t, "../../../../internal/types/testdata/examples", 50, false)
306312
} // TODO(gri) narrow column tolerance
307313
func TestFixedbugs(t *testing.T) {
308314
testDirFiles(t, "../../../../internal/types/testdata/fixedbugs", 100, false)

src/cmd/compile/internal/types2/testdata/local/issue47996.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
package p
66

77
// don't crash
8-
func T /* ERROR missing */ [P] /* ERROR missing */ m /* ERROR unexpected */ () /* ERROR \) */ { /* ERROR { */ } /* ERROR } */
8+
func T /* ERROR "missing" */ [P] /* ERROR "missing" */ m /* ERROR "unexpected" */ () /* ERROR "\)" */ { /* ERROR "{" */ } /* ERROR "}" */

src/go/types/check_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,14 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
222222
index := -1 // errList index of matching message, if any
223223
for i, want := range errList {
224224
pattern := strings.TrimSpace(want.text[len(" ERROR "):])
225+
// We expect all patterns to be quoted in double quotes
226+
// and then we remove the quotes.
227+
// TODO(gri) use correct strconv.Unquote eventually
225228
if n := len(pattern); n >= 2 && pattern[0] == '"' && pattern[n-1] == '"' {
226229
pattern = pattern[1 : n-1]
230+
} else {
231+
t.Errorf("%s:%d:%d: unquoted pattern: %s", filename, line, want.col, pattern)
232+
continue
227233
}
228234
rx, err := regexp.Compile(pattern)
229235
if err != nil {
@@ -326,7 +332,7 @@ func TestManual(t *testing.T) {
326332
}
327333

328334
func TestLongConstants(t *testing.T) {
329-
format := "package longconst\n\nconst _ = %s /* ERROR constant overflow */ \nconst _ = %s // ERROR excessively long constant"
335+
format := `package longconst; const _ = %s /* ERROR "constant overflow" */; const _ = %s // ERROR "excessively long constant"`
330336
src := fmt.Sprintf(format, strings.Repeat("1", 9999), strings.Repeat("1", 10001))
331337
testFiles(t, nil, []string{"longconst.go"}, [][]byte{[]byte(src)}, false, nil)
332338
}
@@ -335,14 +341,14 @@ func TestLongConstants(t *testing.T) {
335341
// be representable as int even if they already have a type that can
336342
// represent larger values.
337343
func TestIndexRepresentability(t *testing.T) {
338-
const src = "package index\n\nvar s []byte\nvar _ = s[int64 /* ERROR \"int64\\(1\\) << 40 \\(.*\\) overflows int\" */ (1) << 40]"
344+
const src = `package index; var s []byte; var _ = s[int64 /* ERROR "int64\(1\) << 40 \(.*\) overflows int" */ (1) << 40]`
339345
testFiles(t, &StdSizes{4, 4}, []string{"index.go"}, [][]byte{[]byte(src)}, false, nil)
340346
}
341347

342348
func TestIssue47243_TypedRHS(t *testing.T) {
343349
// The RHS of the shift expression below overflows uint on 32bit platforms,
344350
// but this is OK as it is explicitly typed.
345-
const src = "package issue47243\n\nvar a uint64; var _ = a << uint64(4294967296)" // uint64(1<<32)
351+
const src = `package issue47243; var a uint64; var _ = a << uint64(4294967296)` // uint64(1<<32)
346352
testFiles(t, &StdSizes{4, 4}, []string{"p.go"}, [][]byte{[]byte(src)}, false, nil)
347353
}
348354

src/go/types/issues_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ import (
574574
func _() {
575575
// Packages should be fully qualified when there is ambiguity within the
576576
// error string itself.
577-
a.F(template /* ERROR cannot use.*html/template.* as .*text/template */ .Template{})
577+
a.F(template /* ERROR "cannot use.*html/template.* as .*text/template" */ .Template{})
578578
}
579579
`
580580
csrc = `
@@ -587,12 +587,12 @@ import (
587587
)
588588
589589
// Issue #46905: make sure template is not the first package qualified.
590-
var _ fmt.Stringer = 1 // ERROR cannot use 1.*as fmt\.Stringer
590+
var _ fmt.Stringer = 1 // ERROR "cannot use 1.*as fmt\.Stringer"
591591
592592
// Packages should be fully qualified when there is ambiguity in reachable
593593
// packages. In this case both a (and for that matter html/template) import
594594
// text/template.
595-
func _() { a.G(template /* ERROR cannot use .*html/template.*Template */ .Template{}) }
595+
func _() { a.G(template /* ERROR "cannot use .*html/template.*Template" */ .Template{}) }
596596
`
597597

598598
tsrc = `
@@ -603,7 +603,7 @@ import "text/template"
603603
type T int
604604
605605
// Verify that the current package name also causes disambiguation.
606-
var _ T = template /* ERROR cannot use.*text/template.* as T value */.Template{}
606+
var _ T = template /* ERROR "cannot use.*text/template.* as T value" */.Template{}
607607
`
608608
)
609609

src/internal/types/testdata/check/blank.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package _ /* ERROR invalid package name */
5+
package _ /* ERROR "invalid package name" */

0 commit comments

Comments
 (0)