From 836356bdaad92d525d65ce01e08305dfbeb7c1e6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 5 Apr 2021 16:06:18 -0700 Subject: [PATCH] cmd/compile/internal/types2: process errors in src order during testing Follow-up on https://golang.org/cl/305573. As a consequence, re-enable test case that caused problems with that CL. Change-Id: Ibffee3f016f4885a55b8e527a5680dd437322209 Reviewed-on: https://go-review.googlesource.com/c/go/+/307216 Trust: Robert Griesemer Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/check_test.go | 14 ++++++++++---- .../internal/types2/fixedbugs/issue39634.go2 | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 2418c29a2f..331f0c7105 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -32,6 +32,7 @@ import ( "os" "path/filepath" "regexp" + "sort" "strings" "testing" @@ -150,6 +151,13 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin return } + // sort errlist in source order + sort.Slice(errlist, func(i, j int) bool { + pi := unpackError(errlist[i]).Pos + pj := unpackError(errlist[j]).Pos + return pi.Cmp(pj) < 0 + }) + // collect expected errors errmap := make(map[string]map[uint][]syntax.Error) for _, filename := range filenames { @@ -165,7 +173,6 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin } // match against found errors - // TODO(gri) sort err list to avoid mismatched when having multiple errors for _, err := range errlist { got := unpackError(err) @@ -205,9 +212,8 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin // eliminate from list if n := len(list) - 1; n > 0 { - // not the last entry - swap in last element and shorten list by 1 - // TODO(gri) avoid changing the order of entries - list[index] = list[n] + // not the last entry - slide entries down (don't reorder) + copy(list[index:], list[index+1:]) filemap[line] = list[:n] } else { // last entry - remove list from filemap diff --git a/src/cmd/compile/internal/types2/fixedbugs/issue39634.go2 b/src/cmd/compile/internal/types2/fixedbugs/issue39634.go2 index c99903f399..36ad1ba08a 100644 --- a/src/cmd/compile/internal/types2/fixedbugs/issue39634.go2 +++ b/src/cmd/compile/internal/types2/fixedbugs/issue39634.go2 @@ -41,8 +41,7 @@ type foo9[A any] interface { type foo9 /* ERROR interface contains type constrai func _() { var _ = new(foo9 /* ERROR interface contains type constraints */ [int]) } // crash 12 -// TODO(gri) temporarily disabled due to an error check issue -// var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len)]c /* ERROR undeclared */ /* ERROR undeclared */ +var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undeclared */ /* ERROR undeclared */ // crash 15 func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }