From e67ce5ea7bddf0a54d4945fc0e4ef74e9271b9dc Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 9 Mar 2021 19:25:31 +0800 Subject: [PATCH] cgen: fix error of alias interpolation (#9209) --- vlib/v/gen/c/str.v | 6 +++++- vlib/v/tests/string_interpolation_alias_test.v | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index 37f27cbe98..3e531089e2 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -204,7 +204,11 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { break } g.write(escaped_val) - typ := g.unwrap_generic(node.expr_types[i]) + mut typ := g.unwrap_generic(node.expr_types[i]) + sym := g.table.get_type_symbol(typ) + if sym.kind == .alias { + typ = (sym.info as table.Alias).parent_type + } // write correct format specifier to intermediate string g.write('%') fspec := node.fmts[i] diff --git a/vlib/v/tests/string_interpolation_alias_test.v b/vlib/v/tests/string_interpolation_alias_test.v index 6d620eb180..cb576e07db 100644 --- a/vlib/v/tests/string_interpolation_alias_test.v +++ b/vlib/v/tests/string_interpolation_alias_test.v @@ -15,3 +15,11 @@ fn test_map_alias_string() { assert '$m'.contains("'one': '1'") assert '$m'.contains("'two': '2'") } + +type Duration = i64 + +fn test_i64_number_alias_string() { + x := i64(9_123_456_789) + y := Duration(x) + assert '$x' == '$y' +}