mirror of
https://github.com/golang/go
synced 2024-11-14 13:10:21 -07:00
b8a410c434
The posBaseMap is used to identify a file's syntax tree node given a source position. The position is mapped to the file base which is then used to look up the file node in posBaseMap. When posBaseMap is initialized, the file position base is not the file base if there's a line directive before the package clause. This can happen in cgo-generated files, for instance due to an import "C" declaration. If the wrong file position base is used during initialization, looking up a file given a position will not find the file. If a version error occurs and the corresponding file is not found, the old code panicked with a null pointer exception. Make sure to consistently initialize the posBaseMap by factoring out the code computing the file base from a given position. While at it, check for a nil file pointer. This should not happen anymore, but don't crash if it happens (at the cost of a slightly less informative error message). Fixes #67141. Change-Id: I4a6af88699c32ad01fffce124b06bb7f9e06f43d Reviewed-on: https://go-review.googlesource.com/c/go/+/586238 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Griesemer <gri@google.com>
16 lines
301 B
Go
16 lines
301 B
Go
// errorcheck -lang=go1.22
|
|
|
|
//go:build go1.21
|
|
|
|
// We need a line directive before the package clause,
|
|
// but don't change file name or position so that the
|
|
// error message appears at the right place.
|
|
|
|
//line issue67141.go:10
|
|
package p
|
|
|
|
func _() {
|
|
for range 10 { // ERROR "cannot range over 10"
|
|
}
|
|
}
|