aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2023-08-07 17:03:43 -0400
committerGopher Robot <gobot@golang.org>2023-08-15 19:04:26 +0000
commit3475e6af4cd6ab7d28ea5a7613eff65be140fbb9 (patch)
tree3197c8a08d11bdcd46f384ebd9dd323607c3ebc5
parent179821c9e12d18c8134429fabe50d3dfaecb948e (diff)
downloadgo-3475e6af4cd6ab7d28ea5a7613eff65be140fbb9.tar.gz
go-3475e6af4cd6ab7d28ea5a7613eff65be140fbb9.zip
[release-branch.go1.21] cmd/go: fix missing case checking for empty slice
When we were comparing the first element of import stacks when sorting depserrors we checked if the first stack was non empty, but not the second one. Do the check for both stacks. Fixes #61818 Updates #61816 For #59905 Change-Id: Id5c11c2b1104eec93196a08c53372ee2ba97c701 Reviewed-on: https://go-review.googlesource.com/c/go/+/516739 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> (cherry picked from commit 58447d757c233f2a9c3c5a73e2d96a6885f2759a) Reviewed-on: https://go-review.googlesource.com/c/go/+/519658 Reviewed-by: Michael Matloob <matloob@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--src/cmd/go/internal/list/list.go3
-rw-r--r--src/cmd/go/testdata/script/list_issue_59905.txt26
2 files changed, 27 insertions, 2 deletions
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index 79120e6a99..92020da946 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -959,7 +959,10 @@ func collectDepsErrors(p *load.Package) {
if len(stkj) != 0 {
return true
}
+
return p.DepsErrors[i].Err.Error() < p.DepsErrors[j].Err.Error()
+ } else if len(stkj) == 0 {
+ return false
}
pathi, pathj := stki[len(stki)-1], stkj[len(stkj)-1]
return pathi < pathj
diff --git a/src/cmd/go/testdata/script/list_issue_59905.txt b/src/cmd/go/testdata/script/list_issue_59905.txt
index 7480462599..48c40d0d14 100644
--- a/src/cmd/go/testdata/script/list_issue_59905.txt
+++ b/src/cmd/go/testdata/script/list_issue_59905.txt
@@ -1,8 +1,13 @@
# Expect no panic
go list -f '{{if .DepsErrors}}{{.DepsErrors}}{{end}}' -export -e -deps
-cmpenv stdout wanterr
+cmpenv stdout wanterr_59905
--- wanterr --
+# Expect no panic (Issue 61816)
+cp level1b_61816.txt level1b/pkg.go
+go list -f '{{if .DepsErrors}}{{.DepsErrors}}{{end}}' -export -e -deps
+cmpenv stdout wanterr_61816
+
+-- wanterr_59905 --
[# test/main/level1a
level1a${/}pkg.go:5:2: level2x redeclared in this block
level1a${/}pkg.go:4:2: other declaration of level2x
@@ -14,6 +19,23 @@ level1b${/}pkg.go:5:2: level2x redeclared in this block
level1b${/}pkg.go:5:2: "test/main/level1b/level2y" imported as level2x and not used
level1b${/}pkg.go:8:39: undefined: level2y
]
+-- wanterr_61816 --
+[level1b${/}pkg.go:4:2: package foo is not in std ($GOROOT${/}src${/}foo)]
+[# test/main/level1a
+level1a${/}pkg.go:5:2: level2x redeclared in this block
+ level1a${/}pkg.go:4:2: other declaration of level2x
+level1a${/}pkg.go:5:2: "test/main/level1a/level2y" imported as level2x and not used
+level1a${/}pkg.go:8:39: undefined: level2y
+ level1b${/}pkg.go:4:2: package foo is not in std ($GOROOT${/}src${/}foo)]
+-- level1b_61816.txt --
+package level1b
+
+import (
+ "foo"
+)
+
+func Print() { println(level2x.Value, level2y.Value) }
+
-- go.mod --
module test/main