Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: //line problems #22660
I'm trying to fix and test some issues around cmd/cover and line numbers, but I've run into two compiler problems with the processing of //line directives. These seem like they should be easy fixes.
This creates a trivial x.go with a line directive that gives a full path to a non-existent file in the GOROOT root. (The fact that the file does not exist is irrelevant.)
Then the compiler prints an error because there is no package statement in the file. The error should be reported to the fake file name, and it is, except the path name literally says $GOROOT instead of the actual GOROOT directory.
The $GOROOT appears because that's what we do want to write as the file name in the object file and export data. But for error messages we want to see the actual path name. It looks like objabi.AbsFile is being called incorrectly (a bit too early) while handling the //line directive. It looks like the code needs to distinguish between computing PosBase.filename and PosBase.absFilename, and it makes no such distinction.
Line number stack
For example, the error in the case above needs to say just:
@griesemer I suspect I didn't consider this (obvious in retrospect) case.
CL 63693 also fixes #21720 which I would say is worse than this one, and was backported to 1.9 for it. So I'm disinclined to just revert it without finding a solution to both cases.
I am out today, but can take a look on Monday if you like.