diff --git a/vlib/v/checker/str.v b/vlib/v/checker/str.v index b6b82b7985ffc9..f5680eabe5d0d3 100644 --- a/vlib/v/checker/str.v +++ b/vlib/v/checker/str.v @@ -85,7 +85,8 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type { c.error('no known default format for type `${c.table.get_type_name(ftyp)}`', node.fmt_poss[i]) } - } else if c.comptime.is_comptime(expr) && c.comptime.get_type(expr) != ast.void_type { + } else if c.comptime.is_comptime(expr) + && c.comptime.get_type_or_default(expr, ast.void_type) != ast.void_type { // still `_` placeholder for comptime variable without specifier node.need_fmts[i] = false } else { diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index 219b1f6e8a1b88..52d9149ac493cd 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -241,7 +241,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { mut fmts := node_.fmts.clone() for i, mut expr in node_.exprs { if g.comptime.is_comptime(expr) { - ctyp := g.comptime.get_type(expr) + ctyp := g.comptime.get_type_or_default(expr, node_.expr_types[i]) if ctyp != ast.void_type { node_.expr_types[i] = ctyp if node_.fmts[i] == `_` { diff --git a/vlib/v/tests/generics/generics_method_str_overload_test.v b/vlib/v/tests/generics/generics_method_str_overload_test.v index 65572b44cb98f4..0251548534b589 100644 --- a/vlib/v/tests/generics/generics_method_str_overload_test.v +++ b/vlib/v/tests/generics/generics_method_str_overload_test.v @@ -5,7 +5,7 @@ struct Gen[G] { } fn (g Gen[G]) str() string { - return 'Gen<${G.name}>{${g.id}, ${g.data.str()}, ${g.size}}' + return 'Gen<${G.name}>{${g.id}, ${g.data}, ${g.size}}' } fn test_generics_method_str_overload() {