1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: put the opening brace on a new line again for infix (#8336)

This commit is contained in:
Lukas Neubert 2021-01-26 11:19:32 +01:00 committed by GitHub
parent 3790bd67e3
commit 2007dbc7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -1537,7 +1537,8 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
}
if call_expr.generic_types.len > 0 && method.return_type != 0 {
if typ := c.resolve_generic_type(method.return_type, method.generic_names,
call_expr.generic_types) {
call_expr.generic_types)
{
call_expr.return_type = typ
return typ
}

View File

@ -1564,8 +1564,17 @@ pub fn (mut f Fmt) if_expr(it ast.IfExpr) {
}
if i < it.branches.len - 1 || !it.has_else {
f.write('${dollar}if ')
cur_pos := f.out.len
f.expr(branch.cond)
f.write(' ')
cond_len := f.out.len - cur_pos
is_cond_wrapped := cond_len > 0
&& (branch.cond is ast.IfGuardExpr || branch.cond is ast.CallExpr)
&& '\n' in f.out.last_n(cond_len)
if is_cond_wrapped {
f.writeln('')
} else {
f.write(' ')
}
}
f.write('{')
if single_line {

View File

@ -0,0 +1,12 @@
fn get_typ() Type {
{
{
// The opening brace should be put on a new line here for readability
if typ := c.resolve_generic_type(method.return_type, method.generic_names,
call_expr.generic_types)
{
return typ
}
}
}
}

View File

@ -0,0 +1,10 @@
fn get_typ() Type {
{
{
// The opening brace should be put on a new line here for readability
if typ := c.resolve_generic_type(method.return_type, method.generic_names, call_expr.generic_types) {
return typ
}
}
}
}