Skip to content

reflect: getting the type name as string of a generic type #4098

Open
@nicksinch

Description

@nicksinch

I have a encountered an issue when trying to get the whole type name as string of a generic type and I was able to create a small example to reproduce it.
When running the code in standard Go, the program prints: Herd[main.Wolf] , however, with TinyGo, it prints Herd omitting the type parameter of the generic struct:

Env: tinygo version 0.30.0 darwin/amd64 (using go version go1.21.6 and LLVM version 16.0.1)

tinygo run -target=wasi main.go

package main

import "reflect"

type Animal interface {
	sound()
}

type Wolf struct{}

func (w Wolf) sound() {}

type Herd[T Animal] struct{}

func main() {
	wolvesHerd := Herd[Wolf]{}
	herdVal := reflect.ValueOf(wolvesHerd)
	typeName := herdVal.Type().Name()
	println(typeName)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    reflectionNeeds further work on reflection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions