reflect: implement PtrTo
Этот коммит содержится в:
родитель
36db75b366
коммит
3010466c55
2 изменённых файлов: 15 добавлений и 0 удалений
|
@ -133,6 +133,14 @@ func TypeOf(i interface{}) Type {
|
||||||
return ValueOf(i).typecode
|
return ValueOf(i).typecode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PtrTo(t Type) Type {
|
||||||
|
ptrType := t<<5 | 5 // 0b0101 == 5
|
||||||
|
if ptrType>>5 != t {
|
||||||
|
panic("reflect: PtrTo type does not fit")
|
||||||
|
}
|
||||||
|
return ptrType
|
||||||
|
}
|
||||||
|
|
||||||
func (t Type) String() string {
|
func (t Type) String() string {
|
||||||
return "T"
|
return "T"
|
||||||
}
|
}
|
||||||
|
|
7
testdata/reflect.go
предоставленный
7
testdata/reflect.go
предоставленный
|
@ -265,6 +265,13 @@ func main() {
|
||||||
println("type assertion failed (but should succeed)")
|
println("type assertion failed (but should succeed)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if reflect.TypeOf(new(myint)) != reflect.PtrTo(reflect.TypeOf(myint(0))) {
|
||||||
|
println("PtrTo failed for type myint")
|
||||||
|
}
|
||||||
|
if reflect.TypeOf(new(myslice)) != reflect.PtrTo(reflect.TypeOf(make(myslice, 0))) {
|
||||||
|
println("PtrTo failed for type myslice")
|
||||||
|
}
|
||||||
|
|
||||||
println("\nstruct tags")
|
println("\nstruct tags")
|
||||||
TestStructTag()
|
TestStructTag()
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче