go/types doesn't make a copy of the syntax trees for "copied" constant expressions in grouped constant declarations; it evaluates them with the correct iota value but at their original position. As a result we get the wrong line numbers in the result. I'm amazed this has not come up in the last few years of go/types use.
One possibility might be to remember a line correction delta when we evaluate an expression containing an iota. The line correction delta is the iota value.
Follow-up: @findleyr I think I've got a fairly simple fix for this. Need to rethink/test/clean up etc. but hopefully should be ready sometime tomorrow or over the weekend.
Thanks for investigating this @griesemer. I'm not sure I understand your point about using the iota value to compute correction delta, since there need not be any correlation between iota value and line number, for example https://play.golang.org/p/FQfRsDMMv8v.
@findleyr Yes, you're correct - I've realized that last night as well. Turns out we just need to remember the position of the actual constant being initialized; in fact we need that position anyway to be able to position the error correctly. In short: Whenever we evaluate a constant initialization expression that is "inherited" from (shared with) other constants, we remember the position of the constant identifier. If there's an error in the initialization expression, we use the position of the constant identifier (this is stored in the current Checker context) for the error location (and we can still point to the original expression as well).
…for inherited const init expression
Enabled fixedbugs/issue8183.go for run.go with new typechecker
now that issue is fixed.
Trust: Robert Griesemer <firstname.lastname@example.org>
Reviewed-by: Robert Findley <email@example.com>