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/compile: error has incorrect column number #37180

Open
quackenbush opened this issue Feb 12, 2020 · 5 comments
Open

cmd/compile: error has incorrect column number #37180

quackenbush opened this issue Feb 12, 2020 · 5 comments
Milestone

Comments

@quackenbush
Copy link

@quackenbush quackenbush commented Feb 12, 2020

What version of Go are you using (go version)?

$ go version
1.13.7

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/pdq/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.7/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mv/slwhmwcj03d0npjtlsnjcm2m0000gn/T/go-build196033875=/tmp/go-build -gno-record-gcc-switches -fno-common"
pdq@quackbook-air ~/v/simscope $

What did you do?

Playground: https://play.golang.org/p/DyuvyvPwrv6

package main

type ABC struct {
	A string
}

func hello(first string, second string, third bool) {
}

func main() {
var abc ABC
hello("hello", "world", abc)
}

What did you expect to see?

./prog.go:12:24: cannot use abc (type ABC) as type bool in argument to hello

What did you see instead?

./prog.go:12:16: cannot use abc (type ABC) as type bool in argument to hello

NOTE: I removed leading whitespace in the source code to eliminate ambiguity.

The error is pointing to the second argument column ("world" on column 12) instead of the third argument column (abc on column 24).

@dmitshur dmitshur added this to the Backlog milestone Feb 12, 2020
@dmitshur dmitshur changed the title Compile error has incorrect column number cmd/compile: error has incorrect column number Feb 12, 2020
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Feb 12, 2020

Thanks for reporting. Do you know if this happens with older versions of Go too?

/cc @josharian @mdempsky @martisch per owners.

@quackenbush

This comment has been minimized.

Copy link
Author

@quackenbush quackenbush commented Feb 12, 2020

I also tried with 1.11.13 and it gives the same incorrect column.

@mdempsky

This comment has been minimized.

Copy link
Member

@mdempsky mdempsky commented Feb 12, 2020

Yeah, this is a known issue of the Go compiler's AST that we don't have precise column information for identifier use locations. I can't find an issue that captures this though.

A while back I tried preparing https://go-review.googlesource.com/c/go/+/38735 to fix this, but it had a non-negligible compiler performance impact (~4% for go/types and cmd/compile).

@quackenbush

This comment has been minimized.

Copy link
Author

@quackenbush quackenbush commented Feb 12, 2020

Thanks. Not sure if this helps, but if I change "abc" to a primitive type, Go prints the correct column number in the error:

hello("hello", "world", 3.14)
./prog.go:12:25: cannot use 3.14 (type float64) as type bool in argument to hello
@mdempsky

This comment has been minimized.

Copy link
Member

@mdempsky mdempsky commented Feb 12, 2020

Thanks, for confirming. That's consistent with the issue I was describing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.