mirror of
https://github.com/vlang/v.git
synced 2025-09-15 23:42:28 +03:00
This commit is contained in:
parent
0a89f3082d
commit
092358fd24
2 changed files with 8 additions and 1 deletions
|
@ -242,7 +242,7 @@ pub fn get_string_by_idx(idx int) string {
|
||||||
|
|
||||||
// type_of returns the type info of the passed value
|
// type_of returns the type info of the passed value
|
||||||
pub fn type_of[T](val T) Type {
|
pub fn type_of[T](val T) Type {
|
||||||
return g_reflection.types.filter(it.idx == typeof[T]().idx)[0]
|
return g_reflection.types.filter(it.idx == typeof[T]().idx & 0xff00ffff)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_modules returns the module name built with V source
|
// get_modules returns the module name built with V source
|
||||||
|
|
|
@ -86,3 +86,10 @@ fn test_get_string_by_idx() {
|
||||||
file_idx := reflection.get_funcs().filter(it.name == 'all_after_last')[0].file_idx
|
file_idx := reflection.get_funcs().filter(it.name == 'all_after_last')[0].file_idx
|
||||||
assert reflection.get_string_by_idx(file_idx).ends_with('string.v')
|
assert reflection.get_string_by_idx(file_idx).ends_with('string.v')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_ref() {
|
||||||
|
cstr := c'abc' // &u8
|
||||||
|
assert reflection.type_of(cstr).str().contains("name: 'u8'")
|
||||||
|
ptr_user := &User{}
|
||||||
|
assert reflection.type_of(ptr_user).str().contains("name: 'User'")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue