diff options
author | Robert Griesemer <gri@golang.org> | 2022-01-05 12:25:43 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-01-06 21:38:57 +0000 |
commit | c5540e53b1f692a8c977fd1e4ee0915eea66f999 (patch) | |
tree | 07cba0ceb79959e3f2ec9770a9a2e7c1172f8c96 /src/go | |
parent | 10f1ed131cd2cfb5ac4d9aa09888deb1bac6e921 (diff) | |
download | go-c5540e53b1f692a8c977fd1e4ee0915eea66f999.tar.gz go-c5540e53b1f692a8c977fd1e4ee0915eea66f999.zip |
go/types, types2: ensure that signature type bounds are interfaces
Do this by running verification for instantiated signatures
later, after the delayed type parameter set-up had a chance
to wrap type bounds in implicit interfaces where needed.
Fixes #50450
Change-Id: If3ff7dc0be6af14af854830bfddb81112ac575cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/375737
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/go')
-rw-r--r-- | src/go/types/call.go | 26 | ||||
-rw-r--r-- | src/go/types/testdata/fixedbugs/issue50450.go2 | 11 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/go/types/call.go b/src/go/types/call.go index 4156d56d9f..ec6efd2379 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -75,17 +75,21 @@ func (check *Checker) instantiateSignature(pos token.Pos, typ *Signature, targs inst := check.instance(pos, typ, targs, check.bestContext(nil)).(*Signature) assert(len(xlist) <= len(targs)) - tparams := typ.TypeParams().list() - if i, err := check.verify(pos, tparams, targs); err != nil { - // best position for error reporting - pos := pos - if i < len(xlist) { - pos = xlist[i].Pos() - } - check.softErrorf(atPos(pos), _InvalidTypeArg, "%s", err) - } else { - check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist) - } + + // verify instantiation lazily (was issue #50450) + check.later(func() { + tparams := typ.TypeParams().list() + if i, err := check.verify(pos, tparams, targs); err != nil { + // best position for error reporting + pos := pos + if i < len(xlist) { + pos = xlist[i].Pos() + } + check.softErrorf(atPos(pos), _InvalidTypeArg, "%s", err) + } else { + check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist) + } + }) return inst } diff --git a/src/go/types/testdata/fixedbugs/issue50450.go2 b/src/go/types/testdata/fixedbugs/issue50450.go2 new file mode 100644 index 0000000000..bae3111578 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue50450.go2 @@ -0,0 +1,11 @@ +// Copyright 2022 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 + +type S struct{} + +func f[P S]() {} + +var _ = f[S] |