Open
Description
In module mode, if an import
statement refers to a relative path it is currently supposed to fail with relative import not supported
:
go/src/cmd/go/internal/modload/import.go
Lines 245 to 247 in 600a2a4
However, we seem to be missing test coverage for that error message, and the actual error that is printed for that case is substantially different:
$ go version
go version devel go1.17-912f07504 Fri Jul 2 21:06:08 2021 +0000 linux/amd64
$ go build .
main.go:4:2: local import "./foo" in non-local package
-- foo/foo.go --
package foo
-- go.mod --
module example.com/m
go 1.17
-- main.go --
package main
import (
_ "./foo"
)
func main() {}
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/bcmills/.cache/go-build"
GOENV="/usr/local/google/home/bcmills/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/tmp/tmp.8tQ48Pjrac/.gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/tmp.8tQ48Pjrac/.gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/bcmills/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.17-912f07504 Fri Jul 2 21:06:08 2021 +0000"
GCCGO="/usr/local/google/home/bcmills/bin/gccgo"
AR="ar"
CC="gcc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.8tQ48Pjrac/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build181655066=/tmp/go-build -gno-record-gcc-switches"
That error message comes from here:
go/src/cmd/go/internal/load/pkg.go
Line 758 in 600a2a4
which implies that the error returned by importFromModules
is either not produced or not propagated as we expect.
Discovered via https://stackoverflow.com/q/68261085.