V: Being able to know the type of a generic

Created on 1 Nov 2020  路  5Comments  路  Source: vlang/v

Good! Time without going through here.
Congratulations on the support of embedded structs.

I wanted to ask for the support (if it is not planned) of being able to know the type of a generic.
V currently, when using a typeof(T), it returns a 'T' and not the type of the generic, it should return the type of the generic.

The use of type 'T' should also be allowed within the function code. Which V does not currently allow to do, except to be used in the parameters and as a return type.

_V is life, V is love._

Feature Request

Most helpful comment

T already represents a type so typeof(T) is an error just like typeof(int).
I've now implemented typeof(expr).name when expr has generic type T.

All 5 comments

yes, typeof(T) will return the actual type

T already represents a type so typeof(T) is an error just like typeof(int).
I've now implemented typeof(expr).name when expr has generic type T.

type 'T' should also be allowed within the function code

It is supported for a few use cases, but others need fixing. Please file a separate issue with specific use cases.

It is supported for a few use cases, but others need fixing. Please file a separate issue with specific use cases.

Just give me 72 hours to think what things could be done with this

T.name now works too #6783.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markgraydev picture markgraydev  路  3Comments

penguindark picture penguindark  路  3Comments

arg2das picture arg2das  路  3Comments

oleg-kachan picture oleg-kachan  路  3Comments

lobotony picture lobotony  路  3Comments