github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/sync2/runtime2/reflect2/type.go (about)

     1  package reflect2
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  )
     7  
     8  //go:linkname typesByString reflect.typesByString
     9  func typesByString(s string) []unsafe.Pointer
    10  
    11  func TypesByString(s string) []reflect.Type {
    12  	var types []reflect.Type
    13  	for _, t := range typesByString(s) {
    14  		pRtypeType := reflect.ValueOf(reflect.TypeOf(0)).Type()
    15  		rtype := reflect.New(pRtypeType).Elem()
    16  
    17  		ptr := unsafe.Pointer(reflect.ValueOf(rtype).FieldByName("ptr").Pointer())
    18  		*(*unsafe.Pointer)(ptr) = t
    19  
    20  		typ := rtype.Interface().(reflect.Type)
    21  		types = append(types, typ)
    22  	}
    23  	return types
    24  }