From 35ec948de766e7e8854b95edda3a0bb4723a63ec Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 14 Apr 2023 14:25:53 -0400 Subject: [PATCH] go/types,types2: fix panic in reverse type inference when -lang TryBot-Result: Gopher Robot Run-TryBot: Robert Findley --- src/cmd/compile/internal/types2/call.go | 8 +++++++- src/go/types/call.go | 8 +++++++- src/internal/types/testdata/fixedbugs/issue59639.go | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/internal/types/testdata/fixedbugs/issue59639.go diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go index 08c90b9f8f..bf561f2c87 100644 --- a/src/cmd/compile/internal/types2/call.go +++ b/src/cmd/compile/internal/types2/call.go @@ -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. diff --git a/src/go/types/call.go b/src/go/types/call.go index f220efb240..854ce7e406 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -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. diff --git a/src/internal/types/testdata/fixedbugs/issue59639.go b/src/internal/types/testdata/fixedbugs/issue59639.go new file mode 100644 index 0000000000..c82d5b10fa --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue59639.go @@ -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" */ -- 2.48.1