cgen: fix string interpolation for non-standard integer types
parent
34fd148f2f
commit
08fac28c52
|
@ -2284,8 +2284,18 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
|
||||||
g.write('%g')
|
g.write('%g')
|
||||||
} else if sym.kind == .struct_ && !sym.has_method('str') {
|
} else if sym.kind == .struct_ && !sym.has_method('str') {
|
||||||
g.write('%.*s')
|
g.write('%.*s')
|
||||||
|
} else if node.expr_types[i] == table.i16_type {
|
||||||
|
g.write('%"PRId16"')
|
||||||
|
} else if node.expr_types[i] == table.u16_type {
|
||||||
|
g.write('%"PRIu16"')
|
||||||
|
} else if node.expr_types[i] == table.u32_type {
|
||||||
|
g.write('%"PRIu32"')
|
||||||
|
} else if node.expr_types[i] == table.i64_type {
|
||||||
|
g.write('%"PRId64"')
|
||||||
|
} else if node.expr_types[i] == table.u64_type {
|
||||||
|
g.write('%"PRIu64"')
|
||||||
} else {
|
} else {
|
||||||
g.write('%d')
|
g.write('%"PRId32"')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.write('", ')
|
g.write('", ')
|
||||||
|
|
|
@ -75,3 +75,15 @@ fn test_string_interpolation_string_prefix() {
|
||||||
jsjs := '$js$js'
|
jsjs := '$js$js'
|
||||||
assert jsjs == 'jsjs'
|
assert jsjs == 'jsjs'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_inttypes_string_interpolation() {
|
||||||
|
s := i16(-23456)
|
||||||
|
us := u16(54321)
|
||||||
|
i := -1622999040
|
||||||
|
ui := u32(3421958087)
|
||||||
|
l := i64(-7694555558525237396)
|
||||||
|
ul := u64(17234006112912956370)
|
||||||
|
assert '$s $us' == '-23456 54321'
|
||||||
|
assert '$ui $i' == '3421958087 -1622999040'
|
||||||
|
assert '$l $ul' == '-7694555558525237396 17234006112912956370'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue