1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: add very simple nameof token to get type name as string

This commit is contained in:
Nicolas Sauzede
2020-02-05 06:12:33 +01:00
committed by GitHub
parent c595c9eee1
commit 9d4c943d64
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,16 @@
fn simple<T>(p T) string {
tname := nameof(T)
println("Hello generic, I'm an [$tname]")
return tname
}
struct FunkyStruct{ }
fn test_nameof_on_various_types_in_generic() {
assert simple(42) == "int"
assert simple(3.14) == "f32"
assert simple("FuBar") == "string"
assert simple(FunkyStruct{}) == "FunkyStruct"
assert simple(test_nameof_on_various_types_in_generic) == "fn ()"
}