CL 515656 updated go/types to use file base as key in the posVers map,
but introduced a panic when the corresponding *token.File is nil.
Check that pos is valid before performing the lookup.
Fixes #61822
Change-Id: I1ac9d48c831a470de8439a50022ba5f59b3e0bed
Reviewed-on: https://go-review.googlesource.com/c/go/+/516738
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
return true
}
- // If the source file declares its Go version, use that to decide.
- if check.posVers != nil {
- fileStart := check.fset.File(at.Pos()).Pos(0)
+ // If the source file declares its Go version and at references a valid
+ // position, use that to decide.
+ if pos := at.Pos(); pos.IsValid() && check.posVers != nil {
+ fileStart := check.fset.File(pos).Pos(0)
if src, ok := check.posVers[fileStart]; ok && src.major >= 1 {
return !src.before(v)
}
--- /dev/null
+// -lang=go1.19
+
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build go1.20
+
+package p
+
+type I[P any] interface {
+ ~string | ~int
+ Error() P
+}
+
+func _[P I[string]]() {
+ var x P
+ var _ error = x
+}