mirror of
https://github.com/golang/go
synced 2024-11-18 16:44:43 -07:00
0835c73534
In Go 1.7, math/rand.Read was added. Previously, the only package containing "rand.Read" was "crypto/rand". goimports was updated to know that, and zstdlib.go contains a note that it's ambiguous: "rand.Perm": "math/rand", "rand.Prime": "crypto/rand", "rand.Rand": "math/rand", // "rand.Read" is ambiguous "rand.Reader": "crypto/rand", "rand.Seed": "math/rand", "rand.Source": "math/rand", The intention originally was that such ambiguous things would never be resolved, even randomly. But a later change added support for build.Default.SrcDirs, which meant GOROOT was also searched for ambiguous things. Or maybe I forget the history. In any case, when goimports tried to resolve "rand.Read", the findImportStdlib check was returning nothing, which lead to the $GOROOT being searched, where math/rand was picked by chance. That's a dangerous default when the intentional might've been crypto/rand. Special case it and prefer crypto/rand if there's no more specific clue either way. Change-Id: Ib5f8f297f72fa309d5ca9b15a37493df2e17567c Reviewed-on: https://go-review.googlesource.com/24847 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org> |
||
---|---|---|
.. | ||
fix_test.go | ||
fix.go | ||
imports.go | ||
mkindex.go | ||
mkstdlib.go | ||
sortimports.go | ||
zstdlib.go |