This is a clean port of CL 351337 from go/types to types2.
Change-Id: I974bf79fcc1ec0016c38e4c0b361d05f7b44e649
Reviewed-on: https://go-review.googlesource.com/c/go/+/351466
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
// TODO(rfindley): eliminate this function or give it a better name.
func safeUnderlying(typ Type) Type {
if t, _ := typ.(*Named); t != nil {
- return t.resolve(nil).underlying
+ return t.underlying
}
return typ.Underlying()
}
}
var newTArgs []Type
- assert(t.targs.Len() == t.orig.TypeParams().Len())
+ if t.targs.Len() != t.orig.TypeParams().Len() {
+ return Typ[Invalid] // error reported elsewhere
+ }
// already instantiated
dump(">>> %s already instantiated", t)
--- /dev/null
+// Copyright 2021 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 T[U interface{ M() T[U] }] int
+
+type X int
+
+func (X) M() T[X] { return 0 }
--- /dev/null
+// Copyright 2021 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 T[U interface{ M() T /* ERROR "got 2 arguments but 1 type parameters" */ [U, int] }] int
+
+type X int
+
+func (X) M() T[X] { return 0 }