diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index 2d6b172d32..8b3b3c79bc 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -353,8 +353,7 @@ pub fn (input BitField) slice(_start int, _end int) BitField { if start_offset != 0 { for i in 0 .. output_slots - 1 { output.field[i] = u32(input.field[start_slot + i] >> u32(start_offset)) - output.field[i] = output.field[i] | u32(input.field[start_slot + i + - 1] << u32(bitfield.slot_size - start_offset)) + output.field[i] = output.field[i] | u32(input.field[start_slot + i + 1] << u32(bitfield.slot_size - start_offset)) } } else { for i in 0 .. output_slots - 1 { diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 0253193435..be330a669a 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -387,16 +387,22 @@ fn test_mutli_array_clone() { mut a3_2 := a3_1.clone() a3_1[0][0][1] = 0 a3_2[0][1][0] = 0 - assert a3_1 == [[[1, 0], [2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6]]] - assert a3_2 == [[[1, 1], [0, 2], [3, 3]], [[4, 4], [5, 5], [6, 6]]] + assert a3_1 == [[[1, 0], [2, 2], [3, 3]], [[4, 4], [5, 5], + [6, 6], + ]] + assert a3_2 == [[[1, 1], [0, 2], [3, 3]], [[4, 4], [5, 5], + [6, 6], + ]] // 3d array_string mut b3_1 := [[['1', '1'], ['2', '2'], ['3', '3']], [['4', '4'], ['5', '5'], ['6', '6']]] mut b3_2 := b3_1.clone() b3_1[0][0][1] = '0' b3_2[0][1][0] = '0' - assert b3_1 == [[['1', '0'], ['2', '2'], ['3', '3']], [['4', '4'], ['5', '5'], ['6', '6']]] - assert b3_2 == [[['1', '1'], ['0', '2'], ['3', '3']], [['4', '4'], ['5', '5'], ['6', '6']]] + assert b3_1 == [[['1', '0'], ['2', '2'], ['3', '3']], [['4', '4'], + ['5', '5'], ['6', '6']]] + assert b3_2 == [[['1', '1'], ['0', '2'], ['3', '3']], [['4', '4'], + ['5', '5'], ['6', '6']]] } fn test_doubling() { diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index 19911c2e88..4b3a26534d 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -87,12 +87,14 @@ fn test_format_ss() { } fn test_format_ss_milli() { - assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy) + assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, + .ddmmyyyy) assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli() } fn test_format_ss_micro() { - assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy) + assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, + .ddmmyyyy) assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro() } diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 18d84e123c..f843d791a2 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -188,9 +188,11 @@ pub fn (v Builder) get_builtin_files() []string { if os.exists(os.join_path(location, 'builtin')) { mut builtin_files := []string{} if v.pref.is_bare { - builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin', 'bare')) + builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin', + 'bare')) } else if v.pref.backend == .js { - builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin', 'js')) + builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin', + 'js')) } else { builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin')) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f95d7d9c2e..bf886293ef 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2409,7 +2409,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { if assign_stmt.right_types.len < assign_stmt.left.len { // first type or multi return types added above right_type := c.expr(assign_stmt.right[i]) if assign_stmt.right_types.len == i { - assign_stmt.right_types << c.check_expr_opt_call(assign_stmt.right[i], right_type) + assign_stmt.right_types << c.check_expr_opt_call(assign_stmt.right[i], + right_type) } } right := if i < assign_stmt.right.len { assign_stmt.right[i] } else { assign_stmt.right[0] } diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 1396460aba..2e373283f4 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -695,8 +695,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { comment_align_i++ align = comment_aligns[comment_align_i] } - pad_len := align.max_attrs_len - attrs_len + - align.max_type_len - field_types[i].len + pad_len := align.max_attrs_len - attrs_len + align.max_type_len - field_types[i].len f.write(strings.repeat(` `, pad_len)) } f.write(' ') @@ -1449,7 +1448,7 @@ pub fn (mut f Fmt) lock_expr(lex ast.LockExpr) { pub fn (mut f Fmt) infix_expr(node ast.InfixExpr) { buffering_save := f.buffering - if !f.buffering { + if !f.buffering && node.op in [.logical_or, .and, .plus] { f.buffering = true } if node.op == .left_shift { @@ -1587,8 +1586,9 @@ pub fn (mut f Fmt) if_expr(it ast.IfExpr) { f.write(' ') } } - // When a single line if is really long, write it again as multiline - if single_line && f.line_len > fmt.max_len.last() { + // When a single line if is really long, write it again as multiline, + // except it is part of an InfixExpr. + if single_line && f.line_len > fmt.max_len.last() && !f.buffering { single_line = false f.single_line_if = false f.out.go_back(f.line_len - if_start) diff --git a/vlib/v/fmt/tests/concat_expr_expected.vv b/vlib/v/fmt/tests/concat_expr_expected.vv index c876ab8f7a..47d58724ff 100644 --- a/vlib/v/fmt/tests/concat_expr_expected.vv +++ b/vlib/v/fmt/tests/concat_expr_expected.vv @@ -15,3 +15,10 @@ fn concat_inside_ternary() { } } } + +fn concat_two_or_more_ternaries() { + x := if some_condition { 'very long string part' } else { 'def' } + + if y == 'asd' { 'qwe' } else { 'something else' } + var := if other_condition { 'concat three long ternary ifs' } else { 'def' } + + if true { 'shorter' } else { 'quite short' } + if true { 'small' } else { 'tiny' } +} diff --git a/vlib/v/fmt/tests/concat_expr_input.vv b/vlib/v/fmt/tests/concat_expr_input.vv index 9ebe7d0065..383c52ea95 100644 --- a/vlib/v/fmt/tests/concat_expr_input.vv +++ b/vlib/v/fmt/tests/concat_expr_input.vv @@ -15,3 +15,8 @@ fn concat_inside_ternary() { } } } + +fn concat_two_or_more_ternaries() { + x := if some_condition { 'very long string part' } else { 'def' } + if y == 'asd' { 'qwe' } else {'something else'} + var := if other_condition { 'concat three long ternary ifs' } else { 'def' } + if true {'shorter'} else {'quite short'} + if true { 'small' } else {'tiny'} +} diff --git a/vlib/v/gen/auto_str_methods.v b/vlib/v/gen/auto_str_methods.v index e16c4f3114..6fb9e42426 100644 --- a/vlib/v/gen/auto_str_methods.v +++ b/vlib/v/gen/auto_str_methods.v @@ -40,7 +40,9 @@ fn (g &Gen) type_to_fmt(typ table.Type) string { sym := g.table.get_type_symbol(typ) if typ.is_ptr() && (typ.is_int() || typ.is_float()) { return '%.*s\\000' - } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, .function] { + } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, + .function, + ] { return '%.*s\\000' } else if sym.kind == .string { return "'%.*s\\000'" diff --git a/vlib/v/gen/json.v b/vlib/v/gen/json.v index 906d338af8..1da7e2f838 100644 --- a/vlib/v/gen/json.v +++ b/vlib/v/gen/json.v @@ -202,7 +202,9 @@ fn js_dec_name(typ string) string { } fn is_js_prim(typ string) bool { - return typ in ['int', 'string', 'bool', 'f32', 'f64', 'i8', 'i16', 'i64', 'u16', 'u32', 'u64', 'byte'] + return typ in ['int', 'string', 'bool', 'f32', 'f64', 'i8', 'i16', 'i64', 'u16', 'u32', 'u64', + 'byte', + ] } fn (mut g Gen) decode_array(value_type table.Type) string { diff --git a/vlib/v/util/diff.v b/vlib/v/util/diff.v index e974f3c492..90fe7c8c25 100644 --- a/vlib/v/util/diff.v +++ b/vlib/v/util/diff.v @@ -12,7 +12,8 @@ pub fn find_working_diff_command() ?string { if env_difftool.len > 0 { known_diff_tools << env_difftool } - known_diff_tools << ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff', 'code', 'code.cmd'] + known_diff_tools << ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff', + 'code', 'code.cmd'] // NOTE: code.cmd is the Windows variant of the `code` cli tool for diffcmd in known_diff_tools { if diffcmd == 'opendiff' { // opendiff has no `--version` option diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index e0bd405c56..07f6a4bc57 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -232,11 +232,8 @@ pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ? // todo: send error here later return error('trying to write on a closed socket!') } - mut header_len := 2 + if payload_len > 125 { 2 } else { 0 } + if payload_len > 0xffff { - 6 - } else { - 0 - } + mut header_len := 2 + if payload_len > 125 { 2 } else { 0 } + + if payload_len > 0xffff { 6 } else { 0 } if !ws.is_server { header_len += 4 }