godebug icon indicating copy to clipboard operation
godebug copied to clipboard

Preserve line numbers with compiler directives

Open FiloSottile opened this issue 10 years ago • 1 comments

It's possible to annotate lines so that they are treated as different line numbers in stack traces (panics, ...) and logs (test output, ...)

https://golang.org/cmd/gc/

FiloSottile avatar May 18 '15 14:05 FiloSottile

In some cases it will also be possible to preserve the original line number by putting new statements on the same line, e.g.

godebug.Line(ctx, example_in_go_scope, 6); x := mul(1, 2)

vs

godebug.Line(ctx, example_in_go_scope, 6)
//line example-in.go:6
x := mul(1,2)

Given the two snippets above, I think the second one looks better. It is also probably simpler to implement than to implement a mix of line comments and multiple statements on the same line. But it's worth noting the first one as an option.

jeremyschlatter avatar May 19 '15 03:05 jeremyschlatter