func (ts *Tsubster) tstruct(t *types.Type, force bool) *types.Type {
if t.NumFields() == 0 {
if t.HasTParam() || t.HasShape() {
- // For an empty struct, we need to return a new type,
- // since it may now be fully instantiated (HasTParam
- // becomes false).
+ // For an empty struct, we need to return a new type, if
+ // substituting from a generic type or shape type, since it
+ // will change HasTParam/HasShape flags.
return types.NewStruct(t.Pkg(), nil)
}
return t
// tinter substitutes type params in types of the methods of an interface type.
func (ts *Tsubster) tinter(t *types.Type, force bool) *types.Type {
if t.Methods().Len() == 0 {
- if t.HasTParam() {
- // For an empty interface, we need to return a new type,
- // since it may now be fully instantiated (HasTParam
- // becomes false).
+ if t.HasTParam() || t.HasShape() {
+ // For an empty interface, we need to return a new type, if
+ // substituting from a generic type or shape type, since
+ // since it will change HasTParam/HasShape flags.
return types.NewInterface(t.Pkg(), nil, false)
}
return t
--- /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 a
+
+func Marshal[foobar any]() {
+ _ = NewEncoder[foobar]()
+}
+
+func NewEncoder[foobar any]() *Encoder[foobar] {
+ return nil
+}
+
+type Encoder[foobar any] struct {
+}
+
+func (e *Encoder[foobar]) EncodeToken(t Token[foobar]) {
+
+}
+
+type Token[foobar any] any