Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: confusing compiler errors because of _gomod_.go #28569

Closed
Dirbaio opened this issue Nov 2, 2018 · 6 comments
Closed

cmd/go: confusing compiler errors because of _gomod_.go #28569

Dirbaio opened this issue Nov 2, 2018 · 6 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Dirbaio
Copy link

Dirbaio commented Nov 2, 2018

When compiling the following inside a Go module project (containing go.mod in a parent directory):

package main

var string = "variable named 'string'"

func main() {}

you get the following very confusing error message:

dirbaio@jupiter:~/reby/backend/nexus$ go build weirderror/main.go 
# command-line-arguments
/tmp/go-build698262353/b001/_gomod_.go:7:22: string is not a type

It seems this is because there is an autogenerated file trying to declare a variable of type string.

dirbaio@jupiter:~/reby/backend/nexus$ go build -x weirderror/main.go 
WORK=/tmp/go-build835159733
mkdir -p $WORK/b001/
cat >$WORK/b001/_gomod_.go << 'EOF' # internal

		package main
		import _ "unsafe"
		//go:linkname __debug_modinfo__ runtime/debug.modinfo
		var __debug_modinfo__ string
		func init() {
			__debug_modinfo__ = "0w\xaf\f\x92t\b\x02A\xe1\xc1\a\xe6\xd6\x18\xe6path\tgithub.com/rebythecode/backend/nexus/weirderror\nmod\tgithub.com/rebythecode/backend\t(devel)\t\n\xf92C1\x86\x18 r\x00\x82B\x10A\x16\xd8\xf2"
		}
	EOF
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile runtime=/usr/lib/go/pkg/linux_amd64/runtime.a
EOF
cd /home/dirbaio/reby/backend/nexus/weirderror
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p main -complete -buildid _XG4Y2LGaLdfLVCNTPfu/_XG4Y2LGaLdfLVCNTPfu -goversion go1.11.1 -D _/home/dirbaio/reby/backend/nexus/weirderror -importcfg $WORK/b001/importcfg -pack -c=4 ./main.go $WORK/b001/_gomod_.go
# command-line-arguments
/tmp/go-build835159733/b001/_gomod_.go:7:22: string is not a type

This does not happen when trying to build in a non-modules project.

Go version and env:

dirbaio@jupiter:~$ go version
go version go1.11.1 linux/amd64
dirbaio@jupiter:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dirbaio/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dirbaio/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build429522809=/tmp/go-build -gno-record-gcc-switches"
@mvdan
Copy link
Member

mvdan commented Nov 2, 2018

/cc @rsc @bcmills @hyangah, the three people who have touched the code generation in question.

I presume there could be other ways to break it, such as declaring __debug_modinfo__, or assigning to it in one's init function. I'm not sure what a good fix here could be.

@mvdan mvdan added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 2, 2018
@mvdan mvdan changed the title "string is not a type" confusing error message cmd/go: confusing compiler errors because of _gomod_.go Nov 2, 2018
@hyangah
Copy link
Contributor

hyangah commented Nov 5, 2018

@rsc I think it's better to add the info in a way similar to link's -X flag or gc's buildid recording.

@bcmills
Copy link
Contributor

bcmills commented Nov 5, 2018

Can you still reproduce this with a go command built from source?

https://golang.org/cl/134915 should have fixed the string is not a type error. (See #27584.)

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. modules labels Nov 5, 2018
@bcmills bcmills added this to the Go1.12 milestone Nov 5, 2018
@mvdan
Copy link
Member

mvdan commented Nov 5, 2018

You're right @bcmills, the particular error seems like a duplicate. I wonder if we should still be worried about the __debug_modinfo__ name, although that seems extremely unlikely to cause issues.

@bcmills
Copy link
Contributor

bcmills commented Nov 5, 2018

It's theoretically a problem, but empirically much less likely than shadowing string.

@Dirbaio
Copy link
Author

Dirbaio commented Nov 6, 2018

I just checked. The error is not present in current master.

@Dirbaio Dirbaio closed this as completed Nov 6, 2018
@golang golang locked and limited conversation to collaborators Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants