@@ -477,7 +477,15 @@ func (t *rawType) underlying() *rawType {
477477 return t
478478}
479479
480+ func (t * rawType ) ptrtag () uintptr {
481+ return uintptr (unsafe .Pointer (t )) & 0b11
482+ }
483+
480484func (t * rawType ) isNamed () bool {
485+ if tag := t .ptrtag (); tag != 0 {
486+ return false
487+ }
488+
481489 return t .meta & flagNamed != 0
482490}
483491
@@ -502,9 +510,13 @@ func pointerTo(t *rawType) *rawType {
502510
503511 switch t .Kind () {
504512 case Pointer :
513+ if tag := t .ptrtag (); tag < 3 {
514+ return (* rawType )(unsafe .Add (unsafe .Pointer (t ), 1 ))
515+ }
516+
505517 // TODO(dgryski): This is blocking https://github.com/tinygo-org/tinygo/issues/3131
506518 // We need to be able to create types that match existing types to prevent typecode equality.
507- panic ("reflect: cannot make **T type" )
519+ panic ("reflect: cannot make ***** T type" )
508520 case Struct :
509521 return (* structType )(unsafe .Pointer (t )).ptrTo
510522 default :
@@ -581,6 +593,11 @@ func (t *rawType) Kind() Kind {
581593 if t == nil {
582594 return Invalid
583595 }
596+
597+ if tag := t .ptrtag (); tag != 0 {
598+ return Pointer
599+ }
600+
584601 return Kind (t .meta & kindMask )
585602}
586603
@@ -591,6 +608,10 @@ func (t *rawType) Elem() Type {
591608}
592609
593610func (t * rawType ) elem () * rawType {
611+ if tag := t .ptrtag (); tag != 0 {
612+ return (* rawType )(unsafe .Add (unsafe .Pointer (t ), - 1 ))
613+ }
614+
594615 underlying := t .underlying ()
595616 switch underlying .Kind () {
596617 case Pointer :
0 commit comments