fmt: don't add newlines for UnsafeExpr (#6048)

pull/6056/head
Nick Treleaven 2020-08-03 23:29:10 +01:00 committed by GitHub
parent e291c38119
commit c33dbbc216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 13 deletions

View File

@ -56,6 +56,7 @@ jobs:
./v fmt -verify vlib/v/fmt/fmt.v
./v fmt -verify vlib/v/parser/parser.v
./v fmt -verify vlib/v/gen/cgen.v
./v fmt -verify vlib/v/gen/x64/gen.v
# - name: Test v binaries
# run: ./v -silent build-vbinaries

View File

@ -1060,9 +1060,10 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
f.write(')')
}
ast.UnsafeExpr {
f.writeln('unsafe {')
f.stmts(node.stmts)
f.writeln('}')
f.write('unsafe {')
es := node.stmts[0] as ast.ExprStmt
f.expr(es.expr)
f.write('}')
}
}
}

View File

@ -1,6 +1,6 @@
fn unsafe_fn() {
unsafe {
malloc(2)
_ = malloc(2)
}
}

View File

@ -1,5 +1,5 @@
fn unsafe_fn() {
unsafe { malloc(2) }
unsafe { _ = malloc(2) }
}
fn fn_with_defer() {

View File

@ -24,14 +24,8 @@ fn test_ptr_assign() {
fn test_ptr_infix() {
v := 4
mut q := unsafe {
&v - 1
}
q = unsafe {
q + 3
}
mut q := unsafe {&v - 1}
q = unsafe {q + 3}
_ := q
_ := v
}