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 = syntax.StartPos(xlist[i])
+
+ // 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 = syntax.StartPos(xlist[i])
+ }
+ check.softErrorf(pos, "%s", err)
+ } else {
+ check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
}
- check.softErrorf(pos, "%s", err)
- } else {
- check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
- }
+ })
return inst
}
--- /dev/null
+// 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]
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
}
--- /dev/null
+// 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]