cgen: make .alias fields in structs use their proper string format, instead of the default %d (#9197)

pull/9204/head
Vassilis Panagiotopoulos 2021-03-08 23:36:59 +02:00 committed by GitHub
parent 2ed73bf243
commit b893373e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -45,8 +45,7 @@ fn (g &Gen) type_to_fmt(typ table.Type) string {
if typ.is_ptr() && (typ.is_int() || typ.is_float()) { if typ.is_ptr() && (typ.is_int() || typ.is_float()) {
return '%.*s\\000' return '%.*s\\000'
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type,
.function, .function, .alias] {
] {
return '%.*s\\000' return '%.*s\\000'
} else if sym.kind == .string { } else if sym.kind == .string {
return "'%.*s\\000'" return "'%.*s\\000'"

View File

@ -0,0 +1,12 @@
type Duration = i64
struct Abc {
d Duration
}
fn test_string_interpolation_of_alias() {
x := Abc{
d: i64(9_123_456_789)
}
assert '$x' == 'Abc{\n d: Duration(9123456789)\n}'
}