mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
17 lines
388 B
V
17 lines
388 B
V
|
|
||
|
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 ()"
|
||
|
}
|