From 81b30caf18bbc0d9491eb763377b9a0095dd8dc3 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 10 Sep 2023 20:32:22 -0300 Subject: [PATCH] checker: fix typeof of typeof.name (#19323) --- vlib/v/gen/c/comptime.v | 2 +- vlib/v/tests/typeof_name_test.v | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/typeof_name_test.v diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 7491fd3fc31625..877b095ee5cad2 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -795,7 +795,7 @@ fn (mut g Gen) get_comptime_var_type(node ast.Expr) ast.Type { fn (mut g Gen) resolve_comptime_type(node ast.Expr, default_type ast.Type) ast.Type { if (node is ast.Ident && g.is_comptime_var(node)) || node is ast.ComptimeSelector { return g.get_comptime_var_type(node) - } else if node is ast.SelectorExpr { + } else if node is ast.SelectorExpr && node.expr_type != 0 { sym := g.table.sym(g.unwrap_generic(node.expr_type)) if f := g.table.find_field_with_embeds(sym, node.field_name) { return f.typ diff --git a/vlib/v/tests/typeof_name_test.v b/vlib/v/tests/typeof_name_test.v new file mode 100644 index 00000000000000..6cc7472230aaf0 --- /dev/null +++ b/vlib/v/tests/typeof_name_test.v @@ -0,0 +1,6 @@ +fn test_main() { + pi := 3.14 + type_ := typeof(pi).name + assert typeof(type_).name == 'string' + assert typeof(typeof(pi).name).name == 'string' +}