blob: ee4e7bb6edfdd031eb6fc2c06a7550e249a6d0b7 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001package reflect2
2
3import (
4 "reflect"
5 "unsafe"
6)
7
8type safeType struct {
9 reflect.Type
10 cfg *frozenConfig
11}
12
13func (type2 *safeType) New() interface{} {
14 return reflect.New(type2.Type).Interface()
15}
16
17func (type2 *safeType) UnsafeNew() unsafe.Pointer {
18 panic("does not support unsafe operation")
19}
20
21func (type2 *safeType) Elem() Type {
22 return type2.cfg.Type2(type2.Type.Elem())
23}
24
25func (type2 *safeType) Type1() reflect.Type {
26 return type2.Type
27}
28
29func (type2 *safeType) PackEFace(ptr unsafe.Pointer) interface{} {
30 panic("does not support unsafe operation")
31}
32
33func (type2 *safeType) Implements(thatType Type) bool {
34 return type2.Type.Implements(thatType.Type1())
35}
36
37func (type2 *safeType) RType() uintptr {
38 panic("does not support unsafe operation")
39}
40
41func (type2 *safeType) Indirect(obj interface{}) interface{} {
42 return reflect.Indirect(reflect.ValueOf(obj)).Interface()
43}
44
45func (type2 *safeType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
46 panic("does not support unsafe operation")
47}
48
49func (type2 *safeType) LikePtr() bool {
50 panic("does not support unsafe operation")
51}
52
53func (type2 *safeType) IsNullable() bool {
54 return IsNullable(type2.Kind())
55}
56
57func (type2 *safeType) IsNil(obj interface{}) bool {
58 if obj == nil {
59 return true
60 }
61 return reflect.ValueOf(obj).Elem().IsNil()
62}
63
64func (type2 *safeType) UnsafeIsNil(ptr unsafe.Pointer) bool {
65 panic("does not support unsafe operation")
66}
67
68func (type2 *safeType) Set(obj interface{}, val interface{}) {
69 reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(val).Elem())
70}
71
72func (type2 *safeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) {
73 panic("does not support unsafe operation")
74}
75
76func (type2 *safeType) AssignableTo(anotherType Type) bool {
77 return type2.Type1().AssignableTo(anotherType.Type1())
78}