From 5cd805c6df5c8988ea07e2ec1e4c52574b40bbf1 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 8 Dec 2022 16:20:37 -0800 Subject: [PATCH] go/types, types2: distinguish between substring and regexp error patterns Use ERROR for substrings, and ERRORx for regexp error patterns. Correctly unquote patterns for ERROR and ERRORx. Adjust all tests in internal/types/testdata and locally as needed. The changes to internal/types/testdata were made through repeated applications of regexpr find/replace commands and manual cleanups. Fixes #51006. Change-Id: Ib9ec5001243b688bf5aee56b7d4105fb55999ab4 Reviewed-on: https://go-review.googlesource.com/c/go/+/455755 Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer Run-TryBot: Robert Griesemer --- src/cmd/compile/internal/types2/check_test.go | 60 +++++---- .../types2/testdata/local/issue47996.go | 2 +- src/go/types/check_test.go | 62 ++++++---- src/go/types/commentMap_test.go | 4 +- src/go/types/issues_test.go | 8 +- .../types/testdata/check/builtins0.go | 62 +++++----- .../types/testdata/check/builtins1.go | 2 +- .../types/testdata/check/conversions1.go | 74 +++++------ src/internal/types/testdata/check/decls0.go | 2 +- src/internal/types/testdata/check/decls1.go | 12 +- .../types/testdata/check/decls2/decls2a.go | 4 +- .../types/testdata/check/decls2/decls2b.go | 6 +- src/internal/types/testdata/check/decls3.go | 8 +- src/internal/types/testdata/check/errors.go | 38 +++--- src/internal/types/testdata/check/expr0.go | 4 +- src/internal/types/testdata/check/expr1.go | 8 +- src/internal/types/testdata/check/expr2.go | 4 +- src/internal/types/testdata/check/expr3.go | 116 +++++++++--------- src/internal/types/testdata/check/go1_12.go | 2 +- src/internal/types/testdata/check/importC.go | 6 +- .../check/importdecl0/importdecl0b.go | 2 +- .../check/importdecl1/importdecl1b.go | 2 +- src/internal/types/testdata/check/issues0.go | 56 ++++----- src/internal/types/testdata/check/issues1.go | 4 +- .../types/testdata/check/methodsets.go | 10 +- src/internal/types/testdata/check/shifts.go | 28 ++--- src/internal/types/testdata/check/stmt0.go | 58 ++++----- .../types/testdata/check/typeinference.go | 6 +- .../types/testdata/check/typeinst1.go | 10 +- .../types/testdata/check/typeparams.go | 16 +-- src/internal/types/testdata/check/vardecl.go | 18 +-- .../types/testdata/examples/constraints.go | 2 +- .../types/testdata/examples/inference.go | 6 +- .../types/testdata/examples/methods.go | 4 +- src/internal/types/testdata/examples/types.go | 8 +- .../types/testdata/examples/typesets.go | 2 +- .../types/testdata/fixedbugs/54942.go | 4 +- .../types/testdata/fixedbugs/issue28251.go | 2 +- .../types/testdata/fixedbugs/issue39634.go | 2 +- .../types/testdata/fixedbugs/issue39725.go | 4 +- .../types/testdata/fixedbugs/issue39754.go | 2 +- .../types/testdata/fixedbugs/issue39976.go | 2 +- .../types/testdata/fixedbugs/issue40350.go | 2 +- .../types/testdata/fixedbugs/issue41124.go | 14 +-- .../types/testdata/fixedbugs/issue42881.go | 4 +- .../types/testdata/fixedbugs/issue42987.go | 2 +- .../types/testdata/fixedbugs/issue43087.go | 2 +- .../types/testdata/fixedbugs/issue43109.go | 2 +- .../types/testdata/fixedbugs/issue43110.go | 2 +- .../types/testdata/fixedbugs/issue43124.go | 4 +- .../types/testdata/fixedbugs/issue43190.go | 2 +- .../types/testdata/fixedbugs/issue43671.go | 4 +- .../types/testdata/fixedbugs/issue45114.go | 2 +- .../types/testdata/fixedbugs/issue45920.go | 4 +- .../types/testdata/fixedbugs/issue46583.go | 8 +- .../types/testdata/fixedbugs/issue47031.go | 2 +- .../types/testdata/fixedbugs/issue47115.go | 4 +- .../types/testdata/fixedbugs/issue47411.go | 6 +- .../types/testdata/fixedbugs/issue47747.go | 4 +- .../types/testdata/fixedbugs/issue47818.go | 38 +++--- .../types/testdata/fixedbugs/issue47968.go | 4 +- .../types/testdata/fixedbugs/issue48008.go | 2 +- .../types/testdata/fixedbugs/issue48312.go | 4 +- .../types/testdata/fixedbugs/issue48472.go | 4 +- .../types/testdata/fixedbugs/issue48827.go | 8 +- .../types/testdata/fixedbugs/issue49005.go | 4 +- .../types/testdata/fixedbugs/issue49112.go | 4 +- .../types/testdata/fixedbugs/issue49179.go | 8 +- .../types/testdata/fixedbugs/issue49242.go | 10 +- .../types/testdata/fixedbugs/issue49247.go | 4 +- .../types/testdata/fixedbugs/issue49296.go | 4 +- .../types/testdata/fixedbugs/issue49482.go | 2 +- .../types/testdata/fixedbugs/issue49579.go | 2 +- .../types/testdata/fixedbugs/issue49602.go | 4 +- .../types/testdata/fixedbugs/issue49735.go | 4 +- .../types/testdata/fixedbugs/issue49739.go | 4 +- .../types/testdata/fixedbugs/issue50372.go | 10 +- .../types/testdata/fixedbugs/issue50417.go | 20 +-- .../types/testdata/fixedbugs/issue50782.go | 6 +- .../types/testdata/fixedbugs/issue50816.go | 4 +- .../types/testdata/fixedbugs/issue50918.go | 4 +- .../types/testdata/fixedbugs/issue50929.go | 2 +- .../types/testdata/fixedbugs/issue50965.go | 4 +- .../types/testdata/fixedbugs/issue51229.go | 2 +- .../types/testdata/fixedbugs/issue51232.go | 2 +- .../types/testdata/fixedbugs/issue51335.go | 4 +- .../types/testdata/fixedbugs/issue51376.go | 4 +- .../types/testdata/fixedbugs/issue51472.go | 2 +- .../types/testdata/fixedbugs/issue51610.go | 2 +- .../types/testdata/fixedbugs/issue51658.go | 8 +- .../types/testdata/fixedbugs/issue52031.go | 2 +- .../types/testdata/fixedbugs/issue53358.go | 6 +- .../types/testdata/fixedbugs/issue56351.go | 2 +- .../types/testdata/fixedbugs/issue57486.go | 2 +- .../types/testdata/fixedbugs/issue57500.go | 2 +- .../types/testdata/spec/assignability.go | 50 ++++---- .../types/testdata/spec/comparable1.19.go | 8 +- .../types/testdata/spec/comparisons.go | 4 +- .../types/testdata/spec/conversions.go | 40 +++--- 99 files changed, 568 insertions(+), 532 deletions(-) diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 6825133048..c7970c59a6 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -4,20 +4,27 @@ // This file implements a typechecker test harness. The packages specified // in tests are typechecked. Error messages reported by the typechecker are -// compared against the error messages expected in the test files. +// compared against the errors expected in the test files. // -// Expected errors are indicated in the test files by putting a comment -// of the form /* ERROR "rx" */ immediately following an offending token. -// The harness will verify that an error matching the regular expression -// rx is reported at that source position. Consecutive comments may be -// used to indicate multiple errors for the same token position. +// Expected errors are indicated in the test files by putting comments +// of the form /* ERROR pattern */ or /* ERRORx pattern */ (or a similar +// //-style line comment) immediately following the tokens where errors +// are reported. There must be exactly one blank before and after the +// ERROR/ERRORx indicator, and the pattern must be a properly quoted Go +// string. // -// For instance, the following test file indicates that a "not declared" +// The harness will verify that each ERROR pattern is a substring of the +// error reported at that source position, and that each ERRORx pattern +// is a regular expression matching the respective error. +// Consecutive comments may be used to indicate multiple errors reported +// at the same position. +// +// For instance, the following test source indicates that an "undeclared" // error should be reported for the undeclared variable x: // // package p // func f() { -// _ = x /* ERROR "not declared" */ + 1 +// _ = x /* ERROR "undeclared" */ + 1 // } package types2_test @@ -31,6 +38,7 @@ import ( "os" "path/filepath" "regexp" + "strconv" "strings" "testing" @@ -172,7 +180,7 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) { t.Error(err) continue } - if m := syntax.CommentMap(f, regexp.MustCompile("^ ERROR ")); len(m) > 0 { + if m := syntax.CommentMap(f, regexp.MustCompile("^ ERRORx? ")); len(m) > 0 { errmap[filename] = m } f.Close() @@ -195,24 +203,34 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) { // At least one of the errors in errList should match the current error. indices = indices[:0] for i, want := range errList { - pattern := strings.TrimSpace(want.Msg[len(" ERROR "):]) - // We expect all patterns to be quoted in double quotes - // and then we remove the quotes. - // TODO(gri) use correct strconv.Unquote eventually - if n := len(pattern); n >= 2 && pattern[0] == '"' && pattern[n-1] == '"' { - pattern = pattern[1 : n-1] - } else { - t.Errorf("%s:%d:%d: unquoted pattern: %s", filename, line, want.Pos.Col(), pattern) - continue + pattern, substr := strings.CutPrefix(want.Msg, " ERROR ") + if !substr { + var found bool + pattern, found = strings.CutPrefix(want.Msg, " ERRORx ") + if !found { + panic("unreachable") + } } - rx, err := regexp.Compile(pattern) + pattern, err := strconv.Unquote(strings.TrimSpace(pattern)) if err != nil { t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err) continue } - if rx.MatchString(gotMsg) { - indices = append(indices, i) + if substr { + if !strings.Contains(gotMsg, pattern) { + continue + } + } else { + rx, err := regexp.Compile(pattern) + if err != nil { + t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err) + continue + } + if !rx.MatchString(gotMsg) { + continue + } } + indices = append(indices, i) } if len(indices) == 0 { t.Errorf("%s: no error expected: %q", gotPos, gotMsg) diff --git a/src/cmd/compile/internal/types2/testdata/local/issue47996.go b/src/cmd/compile/internal/types2/testdata/local/issue47996.go index 6fb50a611b..375a931f77 100644 --- a/src/cmd/compile/internal/types2/testdata/local/issue47996.go +++ b/src/cmd/compile/internal/types2/testdata/local/issue47996.go @@ -5,4 +5,4 @@ package p // don't crash -func T /* ERROR "missing" */ [P] /* ERROR "missing" */ m /* ERROR "unexpected" */ () /* ERROR "\)" */ { /* ERROR "{" */ } /* ERROR "}" */ +func T /* ERROR "missing" */ [P] /* ERROR "missing" */ m /* ERROR "unexpected" */ () /* ERROR ")" */ { /* ERROR "{" */ } /* ERROR "}" */ diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index ea742f2b90..638355049e 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -4,20 +4,27 @@ // This file implements a typechecker test harness. The packages specified // in tests are typechecked. Error messages reported by the typechecker are -// compared against the error messages expected in the test files. +// compared against the errors expected in the test files. // -// Expected errors are indicated in the test files by putting a comment -// of the form /* ERROR "rx" */ immediately following an offending token. -// The harness will verify that an error matching the regular expression -// rx is reported at that source position. Consecutive comments may be -// used to indicate multiple errors for the same token position. +// Expected errors are indicated in the test files by putting comments +// of the form /* ERROR pattern */ or /* ERRORx pattern */ (or a similar +// //-style line comment) immediately following the tokens where errors +// are reported. There must be exactly one blank before and after the +// ERROR/ERRORx indicator, and the pattern must be a properly quoted Go +// string. // -// For instance, the following test file indicates that a "not declared" +// The harness will verify that each ERROR pattern is a substring of the +// error reported at that source position, and that each ERRORx pattern +// is a regular expression matching the respective error. +// Consecutive comments may be used to indicate multiple errors reported +// at the same position. +// +// For instance, the following test source indicates that an "undeclared" // error should be reported for the undeclared variable x: // // package p // func f() { -// _ = x /* ERROR "not declared" */ + 1 +// _ = x /* ERROR "undeclared" */ + 1 // } package types_test @@ -36,6 +43,7 @@ import ( "path/filepath" "reflect" "regexp" + "strconv" "strings" "testing" @@ -185,7 +193,7 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man // collect expected errors errmap := make(map[string]map[int][]comment) for i, filename := range filenames { - if m := commentMap(srcs[i], regexp.MustCompile("^ ERROR ")); len(m) > 0 { + if m := commentMap(srcs[i], regexp.MustCompile("^ ERRORx? ")); len(m) > 0 { errmap[filename] = m } } @@ -207,24 +215,34 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man // At least one of the errors in errList should match the current error. indices = indices[:0] for i, want := range errList { - pattern := strings.TrimSpace(want.text[len(" ERROR "):]) - // We expect all patterns to be quoted in double quotes - // and then we remove the quotes. - // TODO(gri) use correct strconv.Unquote eventually - if n := len(pattern); n >= 2 && pattern[0] == '"' && pattern[n-1] == '"' { - pattern = pattern[1 : n-1] - } else { - t.Errorf("%s:%d:%d: unquoted pattern: %s", filename, line, want.col, pattern) - continue + pattern, substr := strings.CutPrefix(want.text, " ERROR ") + if !substr { + var found bool + pattern, found = strings.CutPrefix(want.text, " ERRORx ") + if !found { + panic("unreachable") + } } - rx, err := regexp.Compile(pattern) + pattern, err := strconv.Unquote(strings.TrimSpace(pattern)) if err != nil { t.Errorf("%s:%d:%d: %v", filename, line, want.col, err) continue } - if rx.MatchString(gotMsg) { - indices = append(indices, i) + if substr { + if !strings.Contains(gotMsg, pattern) { + continue + } + } else { + rx, err := regexp.Compile(pattern) + if err != nil { + t.Errorf("%s:%d:%d: %v", filename, line, want.col, err) + continue + } + if !rx.MatchString(gotMsg) { + continue + } } + indices = append(indices, i) } if len(indices) == 0 { t.Errorf("%s: no error expected: %q", gotPos, gotMsg) @@ -335,7 +353,7 @@ func TestLongConstants(t *testing.T) { // be representable as int even if they already have a type that can // represent larger values. func TestIndexRepresentability(t *testing.T) { - const src = `package index; var s []byte; var _ = s[int64 /* ERROR "int64\(1\) << 40 \(.*\) overflows int" */ (1) << 40]` + const src = `package index; var s []byte; var _ = s[int64 /* ERRORx "int64\\(1\\) << 40 \\(.*\\) overflows int" */ (1) << 40]` testFiles(t, &StdSizes{4, 4}, []string{"index.go"}, [][]byte{[]byte(src)}, false, nil) } diff --git a/src/go/types/commentMap_test.go b/src/go/types/commentMap_test.go index ef6017a0aa..e0e3f638fa 100644 --- a/src/go/types/commentMap_test.go +++ b/src/go/types/commentMap_test.go @@ -14,8 +14,8 @@ import ( ) type comment struct { - line, col int // comment position - text string // comment text, excluding "//", "/*", or "*/" + line, col int // comment position + text string // comment text, excluding "//", "/*", or "*/" } // commentMap collects all comments in the given src with comment text diff --git a/src/go/types/issues_test.go b/src/go/types/issues_test.go index cbd6ca29e9..bb6b4c3161 100644 --- a/src/go/types/issues_test.go +++ b/src/go/types/issues_test.go @@ -574,7 +574,7 @@ import ( func _() { // Packages should be fully qualified when there is ambiguity within the // error string itself. - a.F(template /* ERROR "cannot use.*html/template.* as .*text/template" */ .Template{}) + a.F(template /* ERRORx "cannot use.*html/template.* as .*text/template" */ .Template{}) } ` csrc = ` @@ -587,12 +587,12 @@ import ( ) // Issue #46905: make sure template is not the first package qualified. -var _ fmt.Stringer = 1 // ERROR "cannot use 1.*as fmt\.Stringer" +var _ fmt.Stringer = 1 // ERRORx "cannot use 1.*as fmt\\.Stringer" // Packages should be fully qualified when there is ambiguity in reachable // packages. In this case both a (and for that matter html/template) import // text/template. -func _() { a.G(template /* ERROR "cannot use .*html/template.*Template" */ .Template{}) } +func _() { a.G(template /* ERRORx "cannot use .*html/template.*Template" */ .Template{}) } ` tsrc = ` @@ -603,7 +603,7 @@ import "text/template" type T int // Verify that the current package name also causes disambiguation. -var _ T = template /* ERROR "cannot use.*text/template.* as T value" */.Template{} +var _ T = template /* ERRORx "cannot use.*text/template.* as T value" */.Template{} ` ) diff --git a/src/internal/types/testdata/check/builtins0.go b/src/internal/types/testdata/check/builtins0.go index 08b6004d1e..9ae696d5b9 100644 --- a/src/internal/types/testdata/check/builtins0.go +++ b/src/internal/types/testdata/check/builtins0.go @@ -35,9 +35,9 @@ func append1() { type S []byte type T string var t T - _ = append(s, "foo" /* ERROR "cannot use .* in argument to append" */ ) + _ = append(s, "foo" /* ERRORx `cannot use .* in argument to append` */ ) _ = append(s, "foo"...) - _ = append(S(s), "foo" /* ERROR "cannot use .* in argument to append" */ ) + _ = append(S(s), "foo" /* ERRORx `cannot use .* in argument to append` */ ) _ = append(S(s), "foo"...) _ = append(s, t /* ERROR "cannot use t" */ ) _ = append(s, t...) @@ -100,7 +100,7 @@ func cap1() { var s [][]byte _ = cap(s) - _ = cap(s... /* ERROR "invalid use of \.\.\." */ ) + _ = cap(s... /* ERROR "invalid use of ..." */ ) } func cap2() { @@ -161,7 +161,7 @@ func close1() { _ = close /* ERROR "used as value" */ (c) var s []chan int - close(s... /* ERROR "invalid use of \.\.\." */ ) + close(s... /* ERROR "invalid use of ..." */ ) } func close2() { @@ -204,9 +204,9 @@ func complex1() { complex /* ERROR "not used" */ (1, 2) var _ complex64 = complex(f32, f32) - var _ complex64 = complex /* ERROR "cannot use .* in variable declaration" */ (f64, f64) + var _ complex64 = complex /* ERRORx `cannot use .* in variable declaration` */ (f64, f64) - var _ complex128 = complex /* ERROR "cannot use .* in variable declaration" */ (f32, f32) + var _ complex128 = complex /* ERRORx `cannot use .* in variable declaration` */ (f32, f32) var _ complex128 = complex(f64, f64) // untyped constants @@ -225,7 +225,7 @@ func complex1() { var s uint _ = complex(1 /* ERROR "integer" */ <> y + x = x /* ERRORx `operand x .* must be integer` */ << y + x = x /* ERRORx `operand x .* must be integer` */ >> y z = z + 1 z = z + -1 @@ -102,8 +102,8 @@ func _(x, y float64, z myfloat64) { z = z /* ERROR "mismatched types" */ * y z = z /* ERROR "mismatched types" */ / y z = z /* ERROR "mismatched types" */ % y - z = z /* ERROR "operand z .* must be integer" */ << y - z = z /* ERROR "operand z .* must be integer" */ >> y + z = z /* ERRORx `operand z .* must be integer` */ << y + z = z /* ERRORx `operand z .* must be integer` */ >> y } type mystring string diff --git a/src/internal/types/testdata/check/expr2.go b/src/internal/types/testdata/check/expr2.go index b00cfc21f8..ebb85eb233 100644 --- a/src/internal/types/testdata/check/expr2.go +++ b/src/internal/types/testdata/check/expr2.go @@ -9,7 +9,7 @@ package expr2 func _bool() { const t = true == true const f = true == false - _ = t /* ERROR "operator .* not defined" */ < f + _ = t /* ERRORx `operator .* not defined` */ < f _ = 0 == t /* ERROR "mismatched types untyped int and untyped bool" */ var b bool var x, y float32 @@ -40,7 +40,7 @@ func arrays() { _ = c == d /* ERROR "mismatched types" */ var e [10]func() int - _ = e /* ERROR "\[10\]func\(\) int cannot be compared" */ == e + _ = e /* ERROR "[10]func() int cannot be compared" */ == e } func structs() { diff --git a/src/internal/types/testdata/check/expr3.go b/src/internal/types/testdata/check/expr3.go index 8cf9482257..da8d54fd1d 100644 --- a/src/internal/types/testdata/check/expr3.go +++ b/src/internal/types/testdata/check/expr3.go @@ -28,22 +28,22 @@ func indexes() { a0 = a[0] _ = a0 var a1 int32 - a1 = a /* ERROR "cannot use .* in assignment" */ [1] + a1 = a /* ERRORx `cannot use .* in assignment` */ [1] _ = a1 _ = a[9] - _ = a[10 /* ERROR "index .* out of bounds" */ ] + _ = a[10 /* ERRORx `index .* out of bounds` */ ] _ = a[1 /* ERROR "overflows" */ <<100] _ = a[1<< /* ERROR "constant shift overflow" */ 1000] // no out-of-bounds follow-on error _ = a[10:] _ = a[:10] _ = a[10:10] - _ = a[11 /* ERROR "index .* out of bounds" */ :] - _ = a[: 11 /* ERROR "index .* out of bounds" */ ] + _ = a[11 /* ERRORx `index .* out of bounds` */ :] + _ = a[: 11 /* ERRORx `index .* out of bounds` */ ] _ = a[: 1 /* ERROR "overflows" */ <<100] _ = a[:10:10] - _ = a[:11 /* ERROR "index .* out of bounds" */ :10] - _ = a[:10:11 /* ERROR "index .* out of bounds" */ ] + _ = a[:11 /* ERRORx `index .* out of bounds` */ :10] + _ = a[:10:11 /* ERRORx `index .* out of bounds` */ ] _ = a[10:0 /* ERROR "invalid slice indices" */ :10] _ = a[0:10:0 /* ERROR "invalid slice indices" */ ] _ = a[10:0 /* ERROR "invalid slice indices" */:0] @@ -51,30 +51,30 @@ func indexes() { pa := &a _ = pa[9] - _ = pa[10 /* ERROR "index .* out of bounds" */ ] + _ = pa[10 /* ERRORx `index .* out of bounds` */ ] _ = pa[1 /* ERROR "overflows" */ <<100] _ = pa[10:] _ = pa[:10] _ = pa[10:10] - _ = pa[11 /* ERROR "index .* out of bounds" */ :] - _ = pa[: 11 /* ERROR "index .* out of bounds" */ ] + _ = pa[11 /* ERRORx `index .* out of bounds` */ :] + _ = pa[: 11 /* ERRORx `index .* out of bounds` */ ] _ = pa[: 1 /* ERROR "overflows" */ <<100] _ = pa[:10:10] - _ = pa[:11 /* ERROR "index .* out of bounds" */ :10] - _ = pa[:10:11 /* ERROR "index .* out of bounds" */ ] + _ = pa[:11 /* ERRORx `index .* out of bounds` */ :10] + _ = pa[:10:11 /* ERRORx `index .* out of bounds` */ ] _ = pa[10:0 /* ERROR "invalid slice indices" */ :10] _ = pa[0:10:0 /* ERROR "invalid slice indices" */ ] _ = pa[10:0 /* ERROR "invalid slice indices" */ :0] _ = &pa /* ERROR "cannot take address" */ [:10] var b [0]int - _ = b[0 /* ERROR "index .* out of bounds" */ ] + _ = b[0 /* ERRORx `index .* out of bounds` */ ] _ = b[:] _ = b[0:] _ = b[:0] _ = b[0:0] _ = b[0:0:0] - _ = b[1 /* ERROR "index .* out of bounds" */ :0:0] + _ = b[1 /* ERRORx `index .* out of bounds` */ :0:0] var s []int _ = s[- /* ERROR "negative" */ 1] @@ -95,7 +95,7 @@ func indexes() { _ = &s /* ERROR "cannot take address" */ [:10] var m map[string]int - _ = m[0 /* ERROR "cannot use .* in map index" */ ] + _ = m[0 /* ERRORx `cannot use .* in map index` */ ] _ = m /* ERROR "cannot slice" */ ["foo" : "bar"] _ = m["foo"] // ok is of type bool @@ -115,10 +115,10 @@ func indexes() { t0 = t[0] _ = t0 var t1 rune - t1 = t /* ERROR "cannot use .* in assignment" */ [2] + t1 = t /* ERRORx `cannot use .* in assignment` */ [2] _ = t1 _ = ("foo" + "bar")[5] - _ = ("foo" + "bar")[6 /* ERROR "index .* out of bounds" */ ] + _ = ("foo" + "bar")[6 /* ERRORx `index .* out of bounds` */ ] const c = "foo" _ = c[- /* ERROR "negative" */ 1] @@ -128,9 +128,9 @@ func indexes() { c0 = c[0] _ = c0 var c2 float32 - c2 = c /* ERROR "cannot use .* in assignment" */ [2] - _ = c[3 /* ERROR "index .* out of bounds" */ ] - _ = ""[0 /* ERROR "index .* out of bounds" */ ] + c2 = c /* ERRORx `cannot use .* in assignment` */ [2] + _ = c[3 /* ERRORx `index .* out of bounds` */ ] + _ = ""[0 /* ERRORx `index .* out of bounds` */ ] _ = c2 _ = s[1<<30] // no compile-time error here @@ -142,8 +142,8 @@ func indexes() { var i, j int ss = "foo"[1:2] ss = "foo"[i:j] - ms = "foo" /* ERROR "cannot use .* in assignment" */ [1:2] - ms = "foo" /* ERROR "cannot use .* in assignment" */ [i:j] + ms = "foo" /* ERRORx `cannot use .* in assignment` */ [1:2] + ms = "foo" /* ERRORx `cannot use .* in assignment` */ [i:j] _, _ = ss, ms } @@ -157,10 +157,10 @@ func (*T) m() {} func method_expressions() { _ = T.a /* ERROR "no field or method" */ _ = T.x /* ERROR "has no method" */ - _ = T.m /* ERROR "invalid method expression T\.m \(needs pointer receiver \(\*T\)\.m\)" */ + _ = T.m /* ERROR "invalid method expression T.m (needs pointer receiver (*T).m)" */ _ = (*T).m - var f func(*T) = T.m /* ERROR "invalid method expression T\.m \(needs pointer receiver \(\*T\)\.m\)" */ + var f func(*T) = T.m /* ERROR "invalid method expression T.m (needs pointer receiver (*T).m)" */ var g func(*T) = (*T).m _, _ = f, g @@ -182,11 +182,11 @@ func struct_literals() { // keyed elements _ = T1{} - _ = T1{a: 0, 1 /* ERROR "mixture of .* elements" */ } + _ = T1{a: 0, 1 /* ERRORx `mixture of .* elements` */ } _ = T1{aa /* ERROR "unknown field" */ : 0} _ = T1{1 /* ERROR "invalid field name" */ : 0} _ = T1{a: 0, s: "foo", u: 0, a /* ERROR "duplicate field" */: 10} - _ = T1{a: "foo" /* ERROR "cannot use .* in struct literal" */ } + _ = T1{a: "foo" /* ERRORx `cannot use .* in struct literal` */ } _ = T1{c /* ERROR "unknown field" */ : 0} _ = T1{T0: { /* ERROR "missing type" */ }} // struct literal element type may not be elided _ = T1{T0: T0{}} @@ -197,7 +197,7 @@ func struct_literals() { _ = T0{1, b /* ERROR "mixture" */ : 2, 3} _ = T0{1, 2} /* ERROR "too few values" */ _ = T0{1, 2, 3, 4 /* ERROR "too many values" */ } - _ = T0{1, "foo" /* ERROR "cannot use .* in struct literal" */, 3.4 /* ERROR "cannot use .*\(truncated\)" */} + _ = T0{1, "foo" /* ERRORx `cannot use .* in struct literal` */, 3.4 /* ERRORx `cannot use .*\(truncated\)` */} // invalid type type P *struct{ @@ -218,26 +218,26 @@ func struct_literals() { func array_literals() { type A0 [0]int _ = A0{} - _ = A0{0 /* ERROR "index .* out of bounds" */} - _ = A0{0 /* ERROR "index .* out of bounds" */ : 0} + _ = A0{0 /* ERRORx `index .* out of bounds` */} + _ = A0{0 /* ERRORx `index .* out of bounds` */ : 0} type A1 [10]int _ = A1{} _ = A1{0, 1, 2} _ = A1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - _ = A1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /* ERROR "index .* out of bounds" */ } + _ = A1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /* ERRORx `index .* out of bounds` */ } _ = A1{- /* ERROR "negative" */ 1: 0} _ = A1{8: 8, 9} - _ = A1{8: 8, 9, 10 /* ERROR "index .* out of bounds" */ } + _ = A1{8: 8, 9, 10 /* ERRORx `index .* out of bounds` */ } _ = A1{0, 1, 2, 0 /* ERROR "duplicate index" */ : 0, 3: 3, 4} _ = A1{5: 5, 6, 7, 3: 3, 4} _ = A1{5: 5, 6, 7, 3: 3, 4, 5 /* ERROR "duplicate index" */ } - _ = A1{10 /* ERROR "index .* out of bounds" */ : 10, 10 /* ERROR "index .* out of bounds" */ : 10} + _ = A1{10 /* ERRORx `index .* out of bounds` */ : 10, 10 /* ERRORx `index .* out of bounds` */ : 10} _ = A1{5: 5, 6, 7, 3: 3, 1 /* ERROR "overflows" */ <<100: 4, 5 /* ERROR "duplicate index" */ } _ = A1{5: 5, 6, 7, 4: 4, 1 /* ERROR "overflows" */ <<100: 4} _ = A1{2.0} _ = A1{2.1 /* ERROR "truncated" */ } - _ = A1{"foo" /* ERROR "cannot use .* in array or slice literal" */ } + _ = A1{"foo" /* ERRORx `cannot use .* in array or slice literal` */ } // indices must be integer constants i := 1 @@ -255,7 +255,7 @@ func array_literals() { var a13 [3]int var a14 [4]int a13 = a1 - a14 = a1 /* ERROR "cannot use .* in assignment" */ + a14 = a1 /* ERRORx `cannot use .* in assignment` */ _, _ = a13, a14 a2 := [...]int{- /* ERROR "negative" */ 1: 0} @@ -303,7 +303,7 @@ func slice_literals() { _ = S0{5: 5, 6, 7, 4: 4, 1 /* ERROR "overflows" */ <<100: 4} _ = S0{2.0} _ = S0{2.1 /* ERROR "truncated" */ } - _ = S0{"foo" /* ERROR "cannot use .* in array or slice literal" */ } + _ = S0{"foo" /* ERRORx `cannot use .* in array or slice literal` */ } // indices must be resolved correctly const index1 = 1 @@ -356,8 +356,8 @@ func map_literals() { _ = M0{} _ = M0{1 /* ERROR "missing key" */ } - _ = M0{1 /* ERROR "cannot use .* in map literal" */ : 2} - _ = M0{"foo": "bar" /* ERROR "cannot use .* in map literal" */ } + _ = M0{1 /* ERRORx `cannot use .* in map literal` */ : 2} + _ = M0{"foo": "bar" /* ERRORx `cannot use .* in map literal` */ } _ = M0{"foo": 1, "bar": 2, "foo" /* ERROR "duplicate key" */ : 3 } _ = map[interface{}]int{2: 1, 2 /* ERROR "duplicate key" */ : 1} @@ -457,7 +457,7 @@ func type_asserts() { _ = myok var t I - _ = t /* ERROR "use of .* outside type switch" */ .(type) + _ = t /* ERRORx `use of .* outside type switch` */ .(type) _ = t /* ERROR "m has pointer receiver" */ .(T) _ = t.(*T) _ = t /* ERROR "missing method m" */ .(T1) @@ -493,62 +493,62 @@ func _calls() { f1(0) f1(x) f1(10.0) - f1() /* ERROR "not enough arguments in call to f1\n\thave \(\)\n\twant \(int\)" */ - f1(x, y /* ERROR "too many arguments in call to f1\n\thave \(int, float32\)\n\twant \(int\)" */ ) - f1(s /* ERROR "cannot use .* in argument" */ ) + f1() /* ERROR "not enough arguments in call to f1\n\thave ()\n\twant (int)" */ + f1(x, y /* ERROR "too many arguments in call to f1\n\thave (int, float32)\n\twant (int)" */ ) + f1(s /* ERRORx `cannot use .* in argument` */ ) f1(x ... /* ERROR "cannot use ..." */ ) f1(g0 /* ERROR "used as value" */ ()) f1(g1()) - f1(g2 /* ERROR "too many arguments in call to f1\n\thave \(float32, string\)\n\twant \(int\)" */ ()) + f1(g2 /* ERROR "too many arguments in call to f1\n\thave (float32, string)\n\twant (int)" */ ()) - f2() /* ERROR "not enough arguments in call to f2\n\thave \(\)\n\twant \(float32, string\)" */ - f2(3.14) /* ERROR "not enough arguments in call to f2\n\thave \(number\)\n\twant \(float32, string\)" */ + f2() /* ERROR "not enough arguments in call to f2\n\thave ()\n\twant (float32, string)" */ + f2(3.14) /* ERROR "not enough arguments in call to f2\n\thave (number)\n\twant (float32, string)" */ f2(3.14, "foo") - f2(x /* ERROR "cannot use .* in argument" */ , "foo") + f2(x /* ERRORx `cannot use .* in argument` */ , "foo") f2(g0 /* ERROR "used as value" */ ()) - f2(g1()) /* ERROR "not enough arguments in call to f2\n\thave \(int\)\n\twant \(float32, string\)" */ + f2(g1()) /* ERROR "not enough arguments in call to f2\n\thave (int)\n\twant (float32, string)" */ f2(g2()) fs() /* ERROR "not enough arguments" */ fs(g0 /* ERROR "used as value" */ ()) - fs(g1 /* ERROR "cannot use .* in argument" */ ()) + fs(g1 /* ERRORx `cannot use .* in argument` */ ()) fs(g2 /* ERROR "too many arguments" */ ()) fs(gs()) fv() fv(1, 2.0, x) - fv(s /* ERROR "cannot use .* in argument" */ ) + fv(s /* ERRORx `cannot use .* in argument` */ ) fv(s...) fv(x /* ERROR "cannot use" */ ...) fv(1, s /* ERROR "too many arguments" */ ...) - fv(gs /* ERROR "cannot use .* in argument" */ ()) - fv(gs /* ERROR "cannot use .* in argument" */ ()...) + fv(gs /* ERRORx `cannot use .* in argument` */ ()) + fv(gs /* ERRORx `cannot use .* in argument` */ ()...) var t T t.fm() t.fm(1, 2.0, x) - t.fm(s /* ERROR "cannot use .* in argument" */ ) + t.fm(s /* ERRORx `cannot use .* in argument` */ ) t.fm(g1()) t.fm(1, s /* ERROR "too many arguments" */ ...) - t.fm(gs /* ERROR "cannot use .* in argument" */ ()) - t.fm(gs /* ERROR "cannot use .* in argument" */ ()...) + t.fm(gs /* ERRORx `cannot use .* in argument` */ ()) + t.fm(gs /* ERRORx `cannot use .* in argument` */ ()...) T.fm(t, ) T.fm(t, 1, 2.0, x) - T.fm(t, s /* ERROR "cannot use .* in argument" */ ) + T.fm(t, s /* ERRORx `cannot use .* in argument` */ ) T.fm(t, g1()) T.fm(t, 1, s /* ERROR "too many arguments" */ ...) - T.fm(t, gs /* ERROR "cannot use .* in argument" */ ()) - T.fm(t, gs /* ERROR "cannot use .* in argument" */ ()...) + T.fm(t, gs /* ERRORx `cannot use .* in argument` */ ()) + T.fm(t, gs /* ERRORx `cannot use .* in argument` */ ()...) var i interface{ fm(x ...int) } = t i.fm() i.fm(1, 2.0, x) - i.fm(s /* ERROR "cannot use .* in argument" */ ) + i.fm(s /* ERRORx `cannot use .* in argument` */ ) i.fm(g1()) i.fm(1, s /* ERROR "too many arguments" */ ...) - i.fm(gs /* ERROR "cannot use .* in argument" */ ()) - i.fm(gs /* ERROR "cannot use .* in argument" */ ()...) + i.fm(gs /* ERRORx `cannot use .* in argument` */ ()) + i.fm(gs /* ERRORx `cannot use .* in argument` */ ()...) fi() fi(1, 2.0, x, 3.14, "foo") diff --git a/src/internal/types/testdata/check/go1_12.go b/src/internal/types/testdata/check/go1_12.go index 56c6d5a4c9..b47d3de147 100644 --- a/src/internal/types/testdata/check/go1_12.go +++ b/src/internal/types/testdata/check/go1_12.go @@ -31,6 +31,6 @@ const ( // signed shift counts var ( s int - _ = 1 << s // ERROR "invalid operation: signed shift count s \(variable of type int\) requires go1.13 or later" + _ = 1 << s // ERROR "invalid operation: signed shift count s (variable of type int) requires go1.13 or later" _ = 1 >> s // ERROR "signed shift count" ) diff --git a/src/internal/types/testdata/check/importC.go b/src/internal/types/testdata/check/importC.go index a91feb653a..2cdf383a08 100644 --- a/src/internal/types/testdata/check/importC.go +++ b/src/internal/types/testdata/check/importC.go @@ -7,9 +7,9 @@ package importC import "C" -import _ /* ERROR "cannot rename import "C"" */ "C" -import foo /* ERROR "cannot rename import "C"" */ "C" -import . /* ERROR "cannot rename import "C"" */ "C" +import _ /* ERROR `cannot rename import "C"` */ "C" +import foo /* ERROR `cannot rename import "C"` */ "C" +import . /* ERROR `cannot rename import "C"` */ "C" // Test cases extracted from issue #22090. diff --git a/src/internal/types/testdata/check/importdecl0/importdecl0b.go b/src/internal/types/testdata/check/importdecl0/importdecl0b.go index c5216a5dec..99e1d1ebdf 100644 --- a/src/internal/types/testdata/check/importdecl0/importdecl0b.go +++ b/src/internal/types/testdata/check/importdecl0/importdecl0b.go @@ -8,7 +8,7 @@ import "math" import m "math" import . "testing" // declares T in file scope -import . /* ERROR ".unsafe. imported and not used" */ "unsafe" +import . /* ERRORx `.unsafe. imported and not used` */ "unsafe" import . "fmt" // declares Println in file scope import ( diff --git a/src/internal/types/testdata/check/importdecl1/importdecl1b.go b/src/internal/types/testdata/check/importdecl1/importdecl1b.go index fc39863764..49ac2d53e6 100644 --- a/src/internal/types/testdata/check/importdecl1/importdecl1b.go +++ b/src/internal/types/testdata/check/importdecl1/importdecl1b.go @@ -4,7 +4,7 @@ package importdecl1 -import . /* ERROR ".unsafe. imported and not used" */ "unsafe" +import . /* ERRORx ".unsafe. imported and not used" */ "unsafe" type B interface { A diff --git a/src/internal/types/testdata/check/issues0.go b/src/internal/types/testdata/check/issues0.go index c8c92ba1ef..6039df951e 100644 --- a/src/internal/types/testdata/check/issues0.go +++ b/src/internal/types/testdata/check/issues0.go @@ -59,7 +59,7 @@ func issue9473(a []int, b ...int) { _ = append(f0()) _ = append(f0(), f0()...) _ = append(f1()) - _ = append(f2 /* ERROR "cannot use .* in argument" */ ()) + _ = append(f2 /* ERRORx `cannot use .* in argument` */ ()) _ = append(f2()... /* ERROR "cannot use ..." */ ) _ = append(f0(), f1 /* ERROR "multiple-value f1" */ ()) _ = append(f0(), f2 /* ERROR "multiple-value f2" */ ()) @@ -70,7 +70,7 @@ func issue9473(a []int, b ...int) { append_(f0()) append_(f0(), f0()...) append_(f1()) - append_(f2 /* ERROR "cannot use .* in argument" */ ()) + append_(f2 /* ERRORx `cannot use .* in argument` */ ()) append_(f2()... /* ERROR "cannot use ..." */ ) append_(f0(), f1 /* ERROR "multiple-value f1" */ ()) append_(f0(), f2 /* ERROR "multiple-value f2" */ ()) @@ -91,7 +91,7 @@ func issue10979() { nosuchtype /* ERROR "undefined: nosuchtype" */ } type _ interface { - fmt.Nosuchtype /* ERROR "undefined: fmt\.Nosuchtype" */ + fmt.Nosuchtype /* ERROR "undefined: fmt.Nosuchtype" */ } type _ interface { nosuchpkg /* ERROR "undefined: nosuchpkg" */ .Nosuchtype @@ -133,35 +133,35 @@ func issue10260() { ) var x I1 - x = T1 /* ERROR "cannot use T1{} .* as I1 value in assignment: T1 does not implement I1 \(method foo has pointer receiver\)" */ {} - _ = x /* ERROR "impossible type assertion: x\.\(T1\)\n\tT1 does not implement I1 \(method foo has pointer receiver\)" */ .(T1) + x = T1 /* ERRORx `cannot use T1{} .* as I1 value in assignment: T1 does not implement I1 \(method foo has pointer receiver\)` */ {} + _ = x /* ERROR "impossible type assertion: x.(T1)\n\tT1 does not implement I1 (method foo has pointer receiver)" */ .(T1) T1{}.foo /* ERROR "cannot call pointer method foo on T1" */ () - x.Foo /* ERROR "x.Foo undefined \(type I1 has no field or method Foo, but does have foo\)" */ () + x.Foo /* ERROR "x.Foo undefined (type I1 has no field or method Foo, but does have foo)" */ () - _ = i2 /* ERROR "impossible type assertion: i2\.\(\*T1\)\n\t\*T1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)" */ .(*T1) + _ = i2 /* ERROR "impossible type assertion: i2.(*T1)\n\t*T1 does not implement I2 (wrong type for method foo)\n\t\thave foo()\n\t\twant foo(int)" */ .(*T1) - i1 = i0 /* ERROR "cannot use i0 .* as I1 value in assignment: I0 does not implement I1 \(missing method foo\)" */ - i1 = t0 /* ERROR ".* t0 .* as I1 .*: \*T0 does not implement I1 \(missing method foo\)" */ - i1 = i2 /* ERROR ".* i2 .* as I1 .*: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)" */ - i1 = t2 /* ERROR ".* t2 .* as I1 .*: \*T2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)" */ - i2 = i1 /* ERROR ".* i1 .* as I2 .*: I1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)" */ - i2 = t1 /* ERROR ".* t1 .* as I2 .*: \*T1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)" */ + i1 = i0 /* ERRORx `cannot use i0 .* as I1 value in assignment: I0 does not implement I1 \(missing method foo\)` */ + i1 = t0 /* ERRORx `.* t0 .* as I1 .*: \*T0 does not implement I1 \(missing method foo\)` */ + i1 = i2 /* ERRORx `.* i2 .* as I1 .*: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)` */ + i1 = t2 /* ERRORx `.* t2 .* as I1 .*: \*T2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)` */ + i2 = i1 /* ERRORx `.* i1 .* as I2 .*: I1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)` */ + i2 = t1 /* ERRORx `.* t1 .* as I2 .*: \*T1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)` */ - _ = func() I1 { return i0 /* ERROR "cannot use i0 .* as I1 value in return statement: I0 does not implement I1 \(missing method foo\)" */ } - _ = func() I1 { return t0 /* ERROR ".* t0 .* as I1 .*: \*T0 does not implement I1 \(missing method foo\)" */ } - _ = func() I1 { return i2 /* ERROR ".* i2 .* as I1 .*: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)" */ } - _ = func() I1 { return t2 /* ERROR ".* t2 .* as I1 .*: \*T2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)" */ } - _ = func() I2 { return i1 /* ERROR ".* i1 .* as I2 .*: I1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)" */ } - _ = func() I2 { return t1 /* ERROR ".* t1 .* as I2 .*: \*T1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)" */ } + _ = func() I1 { return i0 /* ERRORx `cannot use i0 .* as I1 value in return statement: I0 does not implement I1 \(missing method foo\)` */ } + _ = func() I1 { return t0 /* ERRORx `.* t0 .* as I1 .*: \*T0 does not implement I1 \(missing method foo\)` */ } + _ = func() I1 { return i2 /* ERRORx `.* i2 .* as I1 .*: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)` */ } + _ = func() I1 { return t2 /* ERRORx `.* t2 .* as I1 .*: \*T2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)` */ } + _ = func() I2 { return i1 /* ERRORx `.* i1 .* as I2 .*: I1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)` */ } + _ = func() I2 { return t1 /* ERRORx `.* t1 .* as I2 .*: \*T1 does not implement I2 \(wrong type for method foo\)\n\t\thave foo\(\)\n\t\twant foo\(int\)` */ } // a few more - less exhaustive now f := func(I1, I2){} f(i0 /* ERROR "missing method foo" */ , i1 /* ERROR "wrong type for method foo" */ ) - _ = [...]I1{i0 /* ERROR "cannot use i0 .* as I1 value in array or slice literal: I0 does not implement I1 \(missing method foo\)" */ } - _ = [...]I1{i2 /* ERROR "cannot use i2 .* as I1 value in array or slice literal: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)" */ } + _ = [...]I1{i0 /* ERRORx `cannot use i0 .* as I1 value in array or slice literal: I0 does not implement I1 \(missing method foo\)` */ } + _ = [...]I1{i2 /* ERRORx `cannot use i2 .* as I1 value in array or slice literal: I2 does not implement I1 \(wrong type for method foo\)\n\t\thave foo\(int\)\n\t\twant foo\(\)` */ } _ = []I1{i0 /* ERROR "missing method foo" */ } _ = []I1{i2 /* ERROR "wrong type for method foo" */ } _ = map[int]I1{0: i0 /* ERROR "missing method foo" */ } @@ -282,7 +282,7 @@ type issue25301b /* ERROR "invalid recursive type" */ = interface { } type issue25301c interface { - notE // ERROR "non-interface type struct\{\}" + notE // ERROR "non-interface type struct{}" } type notE = struct{} @@ -317,7 +317,7 @@ var issue27346 = [][n /* ERROR "undefined" */ ]int{ 0: {}, } -var issue22467 = map[int][... /* ERROR "invalid use of ..." */ ]int{0: {}} +var issue22467 = map[int][... /* ERROR "invalid use of [...] array" */ ]int{0: {}} // Test that invalid use of ... in parameter lists is recognized // (issue #28281). @@ -334,7 +334,7 @@ func issue28281g() (... /* ERROR "can only use ... with final parameter" */ TT) func issue26234a(f *syn.Prog) { // The error message below should refer to the actual package name (syntax) // not the local package name (syn). - f.foo /* ERROR "f\.foo undefined \(type \*syntax\.Prog has no field or method foo\)" */ + f.foo /* ERROR "f.foo undefined (type *syntax.Prog has no field or method foo)" */ } type T struct { @@ -351,19 +351,19 @@ func issue26234b(x T) { } func issue26234c() { - T.x /* ERROR "T.x undefined \(type T has no method x\)" */ () + T.x /* ERROR "T.x undefined (type T has no method x)" */ () } func issue35895() { // T is defined in this package, don't qualify its name with the package name. - var _ T = 0 // ERROR "cannot use 0 \(untyped int constant\) as T" + var _ T = 0 // ERROR "cannot use 0 (untyped int constant) as T" // There is only one package with name syntax imported, only use the (global) package name in error messages. - var _ *syn.Prog = 0 // ERROR "cannot use 0 \(untyped int constant\) as \*syntax.Prog" + var _ *syn.Prog = 0 // ERROR "cannot use 0 (untyped int constant) as *syntax.Prog" // Because both t1 and t2 have the same global package name (template), // qualify packages with full path name in this case. - var _ t1.Template = t2 /* ERROR "cannot use .* \(value of type .html/template.\.Template\) as .text/template.\.Template" */ .Template{} + var _ t1.Template = t2 /* ERRORx `cannot use .* \(value of type .html/template.\.Template\) as .text/template.\.Template` */ .Template{} } func issue42989(s uint) { diff --git a/src/internal/types/testdata/check/issues1.go b/src/internal/types/testdata/check/issues1.go index efde922cd2..11eed7d273 100644 --- a/src/internal/types/testdata/check/issues1.go +++ b/src/internal/types/testdata/check/issues1.go @@ -33,12 +33,12 @@ type C[T any] interface { // using type bound C func _[T C[T]](x *T) { - x.m /* ERROR "x\.m undefined" */ () + x.m /* ERROR "x.m undefined" */ () } // using an interface literal as bound func _[T interface{ m() }](x *T) { - x.m /* ERROR "x\.m undefined" */ () + x.m /* ERROR "x.m undefined" */ () } func f2[_ interface{ m1(); m2() }]() {} diff --git a/src/internal/types/testdata/check/methodsets.go b/src/internal/types/testdata/check/methodsets.go index 27f6d31f88..5b3e4a296c 100644 --- a/src/internal/types/testdata/check/methodsets.go +++ b/src/internal/types/testdata/check/methodsets.go @@ -29,7 +29,7 @@ type T3 struct { func _() { var ( _ func(T0) = T0.v0 - _ = T0.p0 /* ERROR "invalid method expression T0\.p0 \(needs pointer receiver \(\*T0\)\.p0\)" */ + _ = T0.p0 /* ERROR "invalid method expression T0.p0 (needs pointer receiver (*T0).p0)" */ _ func (*T0) = (*T0).v0 _ func (*T0) = (*T0).p0 @@ -40,7 +40,7 @@ func _() { _ func(T2) = T2.p2 _ func(T3) = T3.v0 - _ func(T3) = T3.p0 /* ERROR "invalid method expression T3\.p0 \(needs pointer receiver \(\*T3\)\.p0\)" */ + _ func(T3) = T3.p0 /* ERROR "invalid method expression T3.p0 (needs pointer receiver (*T3).p0)" */ _ func(T3) = T3.v1 _ func(T3) = T3.p1 _ func(T3) = T3.v2 @@ -196,9 +196,9 @@ func issue5918() { _ func(error) string = error.Error perr = &err - _ = perr.Error /* ERROR "type \*error is pointer to interface, not interface" */ () - _ func() string = perr.Error /* ERROR "type \*error is pointer to interface, not interface" */ - _ func(*error) string = (*error).Error /* ERROR "type \*error is pointer to interface, not interface" */ + _ = perr.Error /* ERROR "type *error is pointer to interface, not interface" */ () + _ func() string = perr.Error /* ERROR "type *error is pointer to interface, not interface" */ + _ func(*error) string = (*error).Error /* ERROR "type *error is pointer to interface, not interface" */ ) type T *interface{ m() int } diff --git a/src/internal/types/testdata/check/shifts.go b/src/internal/types/testdata/check/shifts.go index a9a3e34725..6ae3985aba 100644 --- a/src/internal/types/testdata/check/shifts.go +++ b/src/internal/types/testdata/check/shifts.go @@ -259,26 +259,26 @@ func shifts7() { func shifts8() { // shift examples from shift discussion: better error messages var s uint - _ = 1.0 /* ERROR "shifted operand 1.0 \(type float64\) must be integer" */ <