}
// Check for case-insensitive collisions of import paths.
+ // If modifying, consider changing checkPathCollisions() in
+ // src/cmd/go/internal/modcmd/vendor.go
fold := str.ToFold(p.ImportPath)
if other := foldPath[fold]; other == "" {
foldPath[fold] = p.ImportPath
}
modpkgs[m] = append(modpkgs[m], pkg)
}
+ checkPathCollisions(modpkgs)
includeAllReplacements := false
includeGoVersions := false
}
}
}
+
+// checkPathCollisions will fail if case-insensitive collisions are present.
+// The reason why we do this check in go mod vendor is to keep consistentcy
+// with go build. If modifying, consider changing load() in
+// src/cmd/go/internal/load/pkg.go
+func checkPathCollisions(modpkgs map[module.Version][]string) {
+ var foldPath = make(map[string]string, len(modpkgs))
+ for m := range modpkgs {
+ fold := str.ToFold(m.Path)
+ if other := foldPath[fold]; other == "" {
+ foldPath[fold] = m.Path
+ } else if other != m.Path {
+ base.Fatalf("go.mod: case-insensitive import collision: %q and %q", m.Path, other)
+ }
+ }
+}
--- /dev/null
+! go build
+stderr 'case-insensitive import collision'
+
+! go mod vendor
+stderr 'case-insensitive import collision'
+
+-- foo.go --
+package main
+
+import (
+ _ "example.com/Foo"
+ _ "example.com/foo"
+)
+
+func main() {}
+-- go.mod --
+module play.ground
+
+go 1.14
+
+require (
+ example.com/foo v0.1.0
+ example.com/Foo v0.1.0
+)
+
+replace (
+ example.com/foo => ./foo
+ example.com/Foo => ./foo_alt
+)
+-- foo/go.mod --
+module example.com/foo
+-- foo/foo.go --
+package foo
+
+-- foo_alt/go.mod --
+module example.com/Foo
+-- foo_alt/foo.go --
+package Foo
\ No newline at end of file