1
0
mirror of https://github.com/golang/go synced 2024-07-05 09:50:19 +00:00
go/test/typeparam/issue48185b.dir/a.go
Dan Scales 80783558b0 cmd/compile: make sure imported instantiated types have their methods created
We should be putting a newly instantiated imported type in
Instantiate/doInst onto the instTypeList, so its methods/dictionaries
are instantiated. To do this, we needed a more general way to add a
type to instTypeList, so add NeedInstType(), analogous to
NeedRuntimeType(). This has the extra advantage that now all types
created by the type substituter are added to instTypeList without any
extra code, which was easy to forget. doInst() now correctly calls
NeedInstType().

This is a bit aggressive, since a fully instantiated type in a generic
function/method may never be used, if the generic method is never
instantiated in the local package. But it should be fairly uncommon for
a generic method to mention a fully instantiated type (but it does
happen in this bug).

Fixes both cases mentioned in the bug.

Fixed #48185

Change-Id: I19b5012dfac17e306c8005f8595a648b0ab280d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/347909
Trust: Dan Scales <danscales@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-09-07 20:37:05 +00:00

38 lines
1.0 KiB
Go

// 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 a
import (
"reflect"
"sync"
)
type addressableValue struct{ reflect.Value }
type arshalers[Options, Coder any] struct {
fncVals []typedArshaler[Options, Coder]
fncCache sync.Map // map[reflect.Type]unmarshaler
}
type typedArshaler[Options, Coder any] struct {
typ reflect.Type
fnc func(Options, *Coder, addressableValue) error
}
type UnmarshalOptions1 struct {
// Unmarshalers is a list of type-specific unmarshalers to use.
Unmarshalers *arshalers[UnmarshalOptions1, Decoder1]
}
type Decoder1 struct {
}
func (a *arshalers[Options, Coder]) lookup(fnc func(Options, *Coder, addressableValue) error, t reflect.Type) func(Options, *Coder, addressableValue) error {
return fnc
}
func UnmarshalFuncV2[T any](fn func(UnmarshalOptions1, *Decoder1, T) error) *arshalers[UnmarshalOptions1, Decoder1] {
return &arshalers[UnmarshalOptions1, Decoder1]{}
}