vfmt: fix eating of `n` in `string(x,n)`

pull/6023/head
Delyan Angelov 2020-07-30 12:04:55 +03:00
parent f2c639c869
commit 3883c34b8c
2 changed files with 37 additions and 0 deletions

View File

@ -788,6 +788,10 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
node.typname = f.table.get_type_symbol(node.typ).name node.typname = f.table.get_type_symbol(node.typ).name
f.write(f.type_to_str(node.typ) + '(') f.write(f.type_to_str(node.typ) + '(')
f.expr(node.expr) f.expr(node.expr)
if node.has_arg {
f.write(', ')
f.expr(node.arg)
}
f.write(')') f.write(')')
} }
ast.CallExpr { ast.CallExpr {

View File

@ -0,0 +1,33 @@
fn abc() string {
unsafe {
mut fullpath := vcalloc(4)
fullpath[0] = `a`
fullpath[1] = `b`
fullpath[2] = `c`
fullpath[3] = 0
return string(fullpath)
}
return ''
}
fn def() string {
unsafe {
mut fullpath := vcalloc(4)
fullpath[0] = `a`
fullpath[1] = `b`
fullpath[2] = `c`
fullpath[3] = 0
return string(fullpath, 3)
}
return ''
}
fn main() {
assert 'abc' == abc()
assert 'abc' == def()
abc_str1 := ptr_str(abc().str)
abc_str2 := ptr_str(abc().str)
println('abc_str1: $abc_str1')
println('abc_str2: $abc_str2')
assert abc_str1 != abc_str2
}