Skip to content

Commit 6252013

Browse files
committed
internal: fix unused errors reported by ineffassign
Updates #76704
1 parent c3feb70 commit 6252013

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

internal/goroot/importcfg.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,29 @@ import (
1616
"sync"
1717
)
1818

19-
var (
20-
stdlibPkgfileMap map[string]string
21-
stdlibPkgfileErr error
22-
once sync.Once
23-
)
24-
2519
// PkgfileMap returns a map of package paths to the location on disk
2620
// of the .a file for the package.
2721
// The caller must not modify the map.
2822
func PkgfileMap() (map[string]string, error) {
29-
once.Do(func() {
23+
return sync.OnceValues(func() (map[string]string, error) {
3024
m := make(map[string]string)
3125
output, err := exec.Command("go", "list", "-export", "-e", "-f", "{{.ImportPath}} {{.Export}}", "std", "cmd").Output()
3226
if err != nil {
33-
stdlibPkgfileErr = err
27+
return m, err
3428
}
3529
for line := range strings.SplitSeq(string(output), "\n") {
3630
if line == "" {
3731
continue
3832
}
3933
sp := strings.SplitN(line, " ", 2)
4034
if len(sp) != 2 {
41-
err = fmt.Errorf("determining pkgfile map: invalid line in go list output: %q", line)
42-
return
35+
return m, fmt.Errorf("determining pkgfile map: invalid line in go list output: %q", line)
4336
}
4437
importPath, export := sp[0], sp[1]
4538
if export != "" {
4639
m[importPath] = export
4740
}
4841
}
49-
stdlibPkgfileMap = m
50-
})
51-
return stdlibPkgfileMap, stdlibPkgfileErr
42+
return m, nil
43+
})()
5244
}

internal/imports/sourcex_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func TestSource(t *testing.T) {
7878
opts := imports.Options{}
7979
// ApplyFixes needs a non-nil opts
8080
got, err := imports.ApplyFixes(fixes, "tfile.go", []byte(fx), &opts, 0)
81+
if err != nil {
82+
t.Fatal(err)
83+
}
8184

8285
fxwant := "package main\n\nimport \"bar.com/foo\"\n\nvar _ = foo.Foo\nvar _ = foo.Bar\n"
8386
if diff := cmp.Diff(string(got), fxwant); diff != "" {

0 commit comments

Comments
 (0)