cgen: fix error of alias interpolation (#9209)

pull/9217/head
yuyi 2021-03-09 19:25:31 +08:00 committed by GitHub
parent 114a7db6e5
commit e67ce5ea7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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]

View File

@ -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'
}