1
0
mirror of https://github.com/golang/go synced 2024-11-06 09:36:16 -07:00
go/src/cmd/internal/src
Robert Griesemer 2a5cf48f91 cmd/compile: print columns (not just lines) in error messages
Compiler errors now show the exact line and line byte offset (sometimes
called "column") of where an error occured. For `go tool compile x.go`:

	package p
	const c int = false
	//line foo.go:123
	type t intg

reports

	x.go:2:7: cannot convert false to type int
	foo.go:123[x.go:4:8]: undefined: intg

(Some errors use the "wrong" position for the error message; arguably
the byte offset for the first error should be 15, the position of 'false',
rathen than 7, the position of 'c'. But that is an indepedent issue.)

The byte offset (column) values are measured in bytes; they start at 1,
matching the convention used by editors and IDEs.

Positions modified by //line directives show the line offset only for the
actual source location (in square brackets), not for the "virtual" file and
line number because that code is likely generated and the //line directive
only provides line information.

Because the new format might break existing tools or scripts, printing
of line offsets can be disabled with the new compiler flag -C. We plan
to remove this flag eventually.

Fixes #10324.

Change-Id: I493f5ee6e78457cf7b00025aba6b6e28e50bb740
Reviewed-on: https://go-review.googlesource.com/37970
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-09 23:29:49 +00:00
..
pos_test.go cmd/compile: print columns (not just lines) in error messages 2017-03-09 23:29:49 +00:00
pos.go cmd/compile: print columns (not just lines) in error messages 2017-03-09 23:29:49 +00:00
xpos_test.go cmd/compile,link: generate PC-value tables with inlining information 2017-03-03 21:29:30 +00:00
xpos.go [dev.inline] cmd/internal/src: introduce compact source position representation 2017-01-09 22:43:22 +00:00