go: cmd/compile: make "byte offset on line" error position info available

When a Go source file has an error, only the line number is reported by the go compiler. So for example, with:

package other
import "fmt"
func OtherHello2() {
    fmtxxx.Printf("hello, world from other\n")
}

the Go compiler error message: other\blah.go:4: undefined: fmtxxx This is okay for command line usage, but when Go is invoked by editors and IDEs, it would be an improvement if a full source range was reported - that is, the start offset (line+column) of the error, and the end offset (line+column).

As an example, here’s the error output from the Rust compiler for a similar error:

src\main.rs:8:5: 8:15 error: macro undefined: 'printlnxxx!'
src\main.rs:8     printlnxxx!("Hello world");
                  ^~~~~~~~~~

The Rust compiler goes even further and prints the range in the command-line UI too. That’s not required though, what I’m asking is just the extra offset info reported in the first line. “8:5” is the start of the error range and “8:15” the end of the range. Reporting the error location as an absolute character offset (as opposed to line+column), would also work fine.

With this, IDE’s can reported errors as squiggly lines in a source editor. Example, see how “xxx” is underlined:

sample_basic thumb As a sidenote, https://github.com/GoClipse/goclipse in particular already supports this functionality, but it needs the compiler to report the full source ranges.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 22 (14 by maintainers)

Commits related to this issue

Most upvoted comments