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: drive letter is missing in source file path when reporting error #25263

Closed
alexbrainman opened this issue May 6, 2018 · 9 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@alexbrainman
Copy link
Member

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

go version devel +5cf3e34f96 Sat May 5 16:27:20 2018 +0000 windows/amd64

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

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Alex\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\users\alex\dev
set GORACE=
set GOROOT=c:\users\alex\dev\go
set GOTMPDIR=
set GOTOOLDIR=c:\users\alex\dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alex\AppData\Local\Temp\go-build038240854=/tmp/go-build -gno-record-gcc-switches

What did you do?

c:\>type %GOPATH%\src\a\main.go
package main

func main() {
        a := 1
}

c:\>go build a

What did you expect to see?

# a
c:\users\alex\dev\src\a\main.go:4:2: a declared and not used

What did you see instead?

# a
users\alex\dev\src\a\main.go:4:2: a declared and not used

Alex

@mvdan
Copy link
Member

mvdan commented May 6, 2018

@alexbrainman does this happen with recent stable versions too?

/cc @griesemer

@alexbrainman
Copy link
Member Author

@alexbrainman does this happen with recent stable versions too?

I checked as far as go1.4.3, and it always has been broken.

Alex

@mvdan
Copy link
Member

mvdan commented May 6, 2018

Do tools like gofmt and vet also have the same issue? I'm asking because at the moment the position information they report is slightly different: #24344

@griesemer
Copy link
Contributor

@alexbrainman Does this also occur if you invoke the compiler with the filenames explicitly? For instance, as in:

go tool compile %GOPATH%\src\a\main.go

@alexbrainman
Copy link
Member Author

Do tools like gofmt and vet also have the same issue?

I had to change my program to make gofmt and vet complain:

c:\>type %GOPATH%\src\a\main.go
package main

func main() {
        a :=
}
c:\>gofmt %GOPATH%\src\a\main.go
c:\users\alex\dev\src\a\main.go:5:1: expected operand, found '}'

c:\>go tool vet %GOPATH%\src\a\main.go
vet: c:\users\alex\dev\src\a\main.go: c:\users\alex\dev\src\a\main.go:5:1: expected operand, found '}'
vet: no files checked

So gofmt and vet look OK to me.

Does this also occur if you invoke the compiler with the filenames explicitly?

Compiler also looks OK to me;

c:\>go tool compile %GOPATH%\src\a\main.go
c:\users\alex\dev\src\a\main.go:5:1: syntax error: unexpected }, expecting expression

Alex

@griesemer
Copy link
Contributor

@alexbrainman Thanks for checking. Thus suggests that the bug is actually with the go command, not the compiler.

@griesemer griesemer changed the title cmd/compile: drive letter is missing in source file path when reporting error cmd/go: drive letter is missing in source file path when reporting error May 8, 2018
@griesemer griesemer added this to the Go1.11 milestone May 8, 2018
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 8, 2018
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label May 8, 2018
@alexbrainman
Copy link
Member Author

Thus suggests that the bug is actually with the go command, not the compiler.

Fair enough. I will try and debug this when I have time. Unless someone beats me to it.

Alex

@benshi001
Copy link
Member

benshi001 commented May 14, 2018

I am confused by this issue. I thought the go command tool always tried to convert a absolute path from the compile program to a relative path to current dir.

Since current dir is c: \ , so "c:\users\alex\dev\src\a\main.go" is converted to "users\alex\dev\src\a\main.go", anything I misunderstood?

Or do you mean such a "users\alex\dev\src\a\main.go" is unclear? should be something like ".\users\alex\dev\src\a\main.go" ?

@alexbrainman
Copy link
Member Author

I thought the go command tool always tried to convert a absolute path from the compile program to a relative path to current dir.

Fair enough. users\alex\dev\src\a\main.go is relative of c:\users\alex\dev\src\a\main.go if current directory is c:\.

I also checked my Linux computer, and it behaves the same way:

$ pwd
/
$ cat $GOPATH/src/a/main.go
package main

func main() {
        a := 1
}
$ go build a
# a
home/a/src/a/main.go:4:2: a declared and not used
$

So, it looks like, I confused myself. Sorry for wasting your time.

Closing this as invalid issue.

Alex

@golang golang locked and limited conversation to collaborators May 14, 2019
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants