1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:46:47 -07:00

go/types,types2: fix panic in reverse type inference when -lang<go1.18

Due to reverse type inference, we may not have an index expression when
type-checking a function instantiation. Fix a panic when the index expr
is nil.

Fixes #59639

Change-Id: Ib5de5e49cdb7b339653e4fb775bf5c5fdb3c6907
Reviewed-on: https://go-review.googlesource.com/c/go/+/484757
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
This commit is contained in:
Rob Findley 2023-04-14 14:25:53 -04:00 committed by Robert Findley
parent 7c2550b7bb
commit 35ec948de7
3 changed files with 25 additions and 2 deletions

View File

@ -24,7 +24,13 @@ func (check *Checker) funcInst(tsig *Signature, pos syntax.Pos, x *operand, inst
assert(tsig != nil || inst != nil)
if !check.allowVersion(check.pkg, pos, 1, 18) {
check.versionErrorf(inst.Pos(), "go1.18", "function instantiation")
var posn poser
if inst != nil {
posn = inst.Pos()
} else {
posn = pos
}
check.versionErrorf(posn, "go1.18", "function instantiation")
}
// targs and xlist are the type arguments and corresponding type expressions, or nil.

View File

@ -26,7 +26,13 @@ func (check *Checker) funcInst(tsig *Signature, pos token.Pos, x *operand, ix *t
assert(tsig != nil || ix != nil)
if !check.allowVersion(check.pkg, pos, 1, 18) {
check.softErrorf(inNode(ix.Orig, ix.Lbrack), UnsupportedFeature, "function instantiation requires go1.18 or later")
var posn positioner
if ix != nil {
posn = inNode(ix.Orig, ix.Lbrack)
} else {
posn = atPos(pos)
}
check.softErrorf(posn, UnsupportedFeature, "function instantiation requires go1.18 or later")
}
// targs and xlist are the type arguments and corresponding type expressions, or nil.

View File

@ -0,0 +1,11 @@
// -reverseTypeInference -lang=go1.17
// 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.
package p
func f[P /* ERROR "requires go1.18" */ interface{}](P) {}
var v func(int) = f /* ERROR "requires go1.18" */