diff --git a/vlib/v/reflection/reflection.v b/vlib/v/reflection/reflection.v index 4393ab530d..d412743bf1 100644 --- a/vlib/v/reflection/reflection.v +++ b/vlib/v/reflection/reflection.v @@ -242,7 +242,7 @@ pub fn get_string_by_idx(idx int) string { // type_of returns the type info of the passed value 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 diff --git a/vlib/v/tests/reflection_test.v b/vlib/v/tests/reflection_test.v index a465e41780..ba791d2170 100644 --- a/vlib/v/tests/reflection_test.v +++ b/vlib/v/tests/reflection_test.v @@ -86,3 +86,10 @@ fn test_get_string_by_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') } + +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'") +}