gen: fix interpolation variadic (#7059)
parent
f1965c0510
commit
6a1e0322bd
|
@ -221,6 +221,8 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
|
|||
} else {
|
||||
g.write('*.*s')
|
||||
}
|
||||
} else if typ.has_flag(.variadic) {
|
||||
g.write('.*s')
|
||||
} else if typ.is_float() {
|
||||
g.write('$fmt${fspec:c}')
|
||||
} else if typ.is_pointer() {
|
||||
|
@ -266,6 +268,8 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
|
|||
} else {
|
||||
g.expr(expr)
|
||||
}
|
||||
} else if typ.has_flag(.variadic) {
|
||||
g.gen_expr_to_string(expr, typ)
|
||||
} else if typ == table.bool_type {
|
||||
g.expr(expr)
|
||||
g.write(' ? _SLIT("true") : _SLIT("false")')
|
||||
|
|
|
@ -9,7 +9,7 @@ struct Man {
|
|||
}
|
||||
|
||||
fn my_variadic_function(x ...Man) string {
|
||||
return '$x' // this interpolation should generate .str() methods for Man
|
||||
return '$x' // this interpolation should generate .str() methods for Man
|
||||
}
|
||||
|
||||
fn test_vargs_string_interpolation() {
|
||||
|
@ -29,3 +29,16 @@ fn test_vargs_string_interpolation() {
|
|||
//
|
||||
println(results)
|
||||
}
|
||||
|
||||
fn variadic_int(x ...int) string {
|
||||
return '$x'
|
||||
}
|
||||
|
||||
fn variadic_bool(x ...bool) string {
|
||||
return '$x'
|
||||
}
|
||||
|
||||
fn test_variadic_interpolation() {
|
||||
assert variadic_int(3, 2, 1) == '[3, 2, 1]'
|
||||
assert variadic_bool(true, false, true) == '[true, false, true]'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue