reflect: add pointerTo()
Этот коммит содержится в:
родитель
ca823f9a0d
коммит
3a3de8a778
2 изменённых файлов: 9 добавлений и 3 удалений
|
@ -452,13 +452,19 @@ func TypeOf(i interface{}) Type {
|
|||
func PtrTo(t Type) Type { return PointerTo(t) }
|
||||
|
||||
func PointerTo(t Type) Type {
|
||||
return pointerTo(t.(*rawType))
|
||||
}
|
||||
|
||||
func pointerTo(t *rawType) *rawType {
|
||||
switch t.Kind() {
|
||||
case Pointer:
|
||||
// TODO(dgryski): This is blocking https://github.com/tinygo-org/tinygo/issues/3131
|
||||
// We need to be able to create types that match existing types to prevent typecode equality.
|
||||
panic("reflect: cannot make **T type")
|
||||
case Struct:
|
||||
return (*structType)(unsafe.Pointer(t.(*rawType))).ptrTo
|
||||
return (*structType)(unsafe.Pointer(t)).ptrTo
|
||||
default:
|
||||
return (*elemType)(unsafe.Pointer(t.(*rawType))).ptrTo
|
||||
return (*elemType)(unsafe.Pointer(t)).ptrTo
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1017,7 +1017,7 @@ func Zero(typ Type) Value {
|
|||
// new value of the given type.
|
||||
func New(typ Type) Value {
|
||||
return Value{
|
||||
typecode: PtrTo(typ).(*rawType),
|
||||
typecode: pointerTo(typ.(*rawType)),
|
||||
value: alloc(typ.Size(), nil),
|
||||
flags: valueFlagExported,
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче