From 54b2a75406a4e347cff2825b698f910549d6bd04 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 1 Feb 2022 16:35:02 -0500 Subject: [PATCH] cmd/go/internal/modload: skip deleted entries in UpdateWorkFile Fixes #50958 Change-Id: I25b4f34bea7705525217296471ce97e6a2ab99f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/382245 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob --- src/cmd/go/internal/modload/init.go | 3 +++ .../go/testdata/script/work_use_issue50958.txt | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/cmd/go/testdata/script/work_use_issue50958.txt diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index cdcfbeb8de..23f4efd02a 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -610,6 +610,9 @@ func UpdateWorkFile(wf *modfile.WorkFile) { missingModulePaths := map[string]string{} // module directory listed in file -> abspath modroot for _, d := range wf.Use { + if d.Path == "" { + continue // d is marked for deletion. + } modRoot := d.Path if d.ModulePath == "" { missingModulePaths[d.Path] = modRoot diff --git a/src/cmd/go/testdata/script/work_use_issue50958.txt b/src/cmd/go/testdata/script/work_use_issue50958.txt new file mode 100644 index 0000000000..7a25531f3d --- /dev/null +++ b/src/cmd/go/testdata/script/work_use_issue50958.txt @@ -0,0 +1,17 @@ +go work use -r . +cmp go.work go.work.want + +-- go.mod -- +module example +go 1.18 +-- go.work -- +go 1.18 + +use sub +-- go.work.want -- +go 1.18 + +use . +-- sub/README.txt -- +This directory no longer contains a go.mod file. +