diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v
index fac8332a01..db12e1a07f 100644
--- a/cmd/tools/vdoc/html.v
+++ b/cmd/tools/vdoc/html.v
@@ -265,7 +265,8 @@ fn (vd VDoc) gen_html(d doc.Doc) string {
submod_prefix = if names.len > 1 { names[0] } else { dc.head.name }
mut href_name := './${dc.head.name}.html'
if (cfg.is_vlib && dc.head.name == 'builtin' && !cfg.include_readme) ||
- dc.head.name == 'README' {
+ dc.head.name == 'README'
+ {
href_name = './index.html'
} else if submod_prefix !in vd.docs.map(it.head.name) {
href_name = '#'
@@ -310,7 +311,8 @@ fn (vd VDoc) gen_html(d doc.Doc) string {
} else {
symbols_toc_str
}).replace('{{ contents }}', contents.str()).replace('{{ right_content }}', if cfg.is_multi &&
- vd.docs.len > 1 && d.head.name != 'README' {
+ vd.docs.len > 1 && d.head.name != 'README'
+ {
'
'
} else {
''
@@ -401,7 +403,8 @@ fn html_highlight(code string, tb &table.Table) string {
if token.is_key(tok.lit) || token.is_decl(tok.kind) {
tok_typ = .keyword
} else if tok.kind == .decl_assign || tok.kind.is_assign() || tok.is_unary() ||
- tok.kind.is_relational() || tok.kind.is_infix() {
+ tok.kind.is_relational() || tok.kind.is_infix()
+ {
tok_typ = .operator
}
}
diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v
index d2e7745798..f66c235c07 100644
--- a/cmd/tools/vvet/vvet.v
+++ b/cmd/tools/vvet/vvet.v
@@ -160,7 +160,8 @@ fn (mut vt Vet) vet_file(path string, is_regression_test bool) {
fn (mut vet Vet) vet_line(lines []string, line string, lnumber int) {
// Vet public functions
if line.starts_with('pub fn') ||
- (line.starts_with('fn ') && !(line.starts_with('fn C.') || line.starts_with('fn main'))) {
+ (line.starts_with('fn ') && !(line.starts_with('fn C.') || line.starts_with('fn main')))
+ {
// Scan function declarations for missing documentation
is_pub_fn := line.starts_with('pub fn')
if lnumber > 0 {
diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v
index 6a666cd7be..e4fd1d73b4 100644
--- a/vlib/os/os_c.v
+++ b/vlib/os/os_c.v
@@ -772,7 +772,8 @@ fn normalize_drive_letter(path string) string {
return path
}
if path.len > 2 &&
- path[0] >= `a` && path[0] <= `z` && path[1] == `:` && path[2] == path_separator[0] {
+ path[0] >= `a` && path[0] <= `z` && path[1] == `:` && path[2] == path_separator[0]
+ {
unsafe {
x := &path.str[0]
(*x) = *x - 32
diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v
index 929384fc2e..048168b864 100644
--- a/vlib/os/os_nix.c.v
+++ b/vlib/os/os_nix.c.v
@@ -94,7 +94,8 @@ pub fn ls(path string) ?[]string {
unsafe {
if bptr[0] == 0 ||
(bptr[0] == `.` && bptr[1] == 0) ||
- (bptr[0] == `.` && bptr[1] == `.` && bptr[2] == 0) {
+ (bptr[0] == `.` && bptr[1] == `.` && bptr[2] == 0)
+ {
continue
}
}
diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v
index 0c65ed464c..f5aed9c735 100644
--- a/vlib/v/builder/builder.v
+++ b/vlib/v/builder/builder.v
@@ -237,7 +237,8 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) ?string {
mod_path := module_path(mod)
mut module_lookup_paths := []string{}
if vmod_file_location.vmod_file.len != 0 &&
- vmod_file_location.vmod_folder !in b.module_search_paths {
+ vmod_file_location.vmod_folder !in b.module_search_paths
+ {
module_lookup_paths << vmod_file_location.vmod_folder
}
module_lookup_paths << b.module_search_paths
diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v
index ef6c8caf83..ae512eabd3 100644
--- a/vlib/v/builder/cc.v
+++ b/vlib/v/builder/cc.v
@@ -210,7 +210,8 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
if ccversion := os.exec('cc --version') {
if ccversion.exit_code == 0 {
if ccversion.output.contains('This is free software;') &&
- ccversion.output.contains('Free Software Foundation, Inc.') {
+ ccversion.output.contains('Free Software Foundation, Inc.')
+ {
ccoptions.guessed_compiler = 'gcc'
}
if ccversion.output.contains('clang version ') {
@@ -351,7 +352,8 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
// Without these libs compilation will fail on Linux
// || os.user_os() == 'linux'
if !v.pref.is_bare && v.pref.build_mode != .build_module && v.pref.os in
- [.linux, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .haiku] {
+ [.linux, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .haiku]
+ {
ccoptions.linker_flags << '-lm'
ccoptions.linker_flags << '-lpthread'
// -ldl is a Linux only thing. BSDs have it in libc.
@@ -399,7 +401,8 @@ fn (ccoptions CcompilerOptions) thirdparty_object_args(middle []string) []string
fn (mut v Builder) setup_output_name() {
if !v.pref.is_shared && v.pref.build_mode != .build_module && os.user_os() == 'windows' &&
- !v.pref.out_name.ends_with('.exe') {
+ !v.pref.out_name.ends_with('.exe')
+ {
v.pref.out_name += '.exe'
}
// Output executable name
diff --git a/vlib/v/builder/cflags.v b/vlib/v/builder/cflags.v
index b425046563..8d6c0bdaaa 100644
--- a/vlib/v/builder/cflags.v
+++ b/vlib/v/builder/cflags.v
@@ -21,7 +21,8 @@ fn (mut v Builder) get_os_cflags() []cflag.CFlag {
(flag.os == 'freebsd' && v.pref.os == .freebsd) ||
(flag.os == 'windows' && v.pref.os == .windows) ||
(flag.os == 'mingw' && v.pref.os == .windows && v.pref.ccompiler != 'msvc') ||
- (flag.os == 'solaris' && v.pref.os == .solaris) {
+ (flag.os == 'solaris' && v.pref.os == .solaris)
+ {
flags << flag
}
if flag.os in ctimedefines {
diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v
index 7772fd30b3..c19ee470f6 100644
--- a/vlib/v/checker/check_types.v
+++ b/vlib/v/checker/check_types.v
@@ -58,7 +58,8 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
// TODO i64 as int etc
if (exp_idx in table.pointer_type_idxs ||
exp_idx in table.number_type_idxs) &&
- (got_idx in table.pointer_type_idxs || got_idx in table.number_type_idxs) {
+ (got_idx in table.pointer_type_idxs || got_idx in table.number_type_idxs)
+ {
return true
}
// if exp_idx in pointer_type_idxs && got_idx in pointer_type_idxs {
@@ -67,12 +68,14 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
// see hack in checker IndexExpr line #691
if (got_idx == table.byte_type_idx &&
exp_idx == table.byteptr_type_idx) ||
- (exp_idx == table.byte_type_idx && got_idx == table.byteptr_type_idx) {
+ (exp_idx == table.byte_type_idx && got_idx == table.byteptr_type_idx)
+ {
return true
}
if (got_idx == table.char_type_idx &&
exp_idx == table.charptr_type_idx) ||
- (exp_idx == table.char_type_idx && got_idx == table.charptr_type_idx) {
+ (exp_idx == table.char_type_idx && got_idx == table.charptr_type_idx)
+ {
return true
}
// TODO: this should no longer be needed
@@ -108,13 +111,15 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
// TODO
// accept [] when an expected type is an array
if got_type_sym.kind == .array &&
- exp_type_sym.kind == .array && got_type_sym.name == 'array_void' {
+ exp_type_sym.kind == .array && got_type_sym.name == 'array_void'
+ {
return true
}
// type alias
if (got_type_sym.kind == .alias &&
got_type_sym.parent_idx == exp_idx) ||
- (exp_type_sym.kind == .alias && exp_type_sym.parent_idx == got_idx) {
+ (exp_type_sym.kind == .alias && exp_type_sym.parent_idx == got_idx)
+ {
return true
}
// sum type
@@ -238,7 +243,8 @@ fn (c &Checker) promote_num(left_type table.Type, right_type table.Type) table.T
} else if idx_lo >= table.byte_type_idx { // both operands are unsigned
return type_hi
} else if idx_lo >= table.i8_type_idx &&
- (idx_hi <= table.i64_type_idx || idx_hi == table.rune_type_idx) { // both signed
+ (idx_hi <= table.i64_type_idx || idx_hi == table.rune_type_idx)
+ { // both signed
return if idx_lo == table.i64_type_idx {
type_lo
} else {
@@ -360,7 +366,8 @@ pub fn (c &Checker) get_default_fmt(ftyp table.Type, typ table.Type) byte {
if ftyp in [table.string_type, table.bool_type] ||
sym.kind in
[.enum_, .array, .array_fixed, .struct_, .map, .multi_return, .sum_type, .none_] || ftyp.has_flag(.optional) ||
- sym.has_method('str') {
+ sym.has_method('str')
+ {
return `s`
} else {
return `_`
@@ -376,7 +383,8 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T
mut fmt := node.fmts[i]
// analyze and validate format specifier
if fmt !in
- [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`] {
+ [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`]
+ {
c.error('unknown format specifier `${fmt:c}`', node.fmt_poss[i])
}
if fmt == `_` { // set default representation for type if none has been given
@@ -403,7 +411,8 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T
(typ.is_float() && fmt !in [`E`, `F`, `G`, `e`, `f`, `g`]) ||
(typ.is_pointer() && fmt !in [`p`, `x`, `X`]) ||
(typ.is_string() && fmt != `s`) ||
- (typ.idx() in [table.i64_type_idx, table.f64_type_idx] && fmt == `c`) {
+ (typ.idx() in [table.i64_type_idx, table.f64_type_idx] && fmt == `c`)
+ {
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
node.fmt_poss[i])
}
@@ -438,7 +447,8 @@ pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) {
mut param_elem_sym := c.table.get_type_symbol(param_elem_info.elem_type)
for {
if arg_elem_sym.kind == .array &&
- param_elem_sym.kind == .array && param_elem_sym.name != 'T' {
+ param_elem_sym.kind == .array && param_elem_sym.name != 'T'
+ {
arg_elem_info = arg_elem_sym.info as table.Array
arg_elem_sym = c.table.get_type_symbol(arg_elem_info.elem_type)
param_elem_info = param_elem_sym.info as table.Array
diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v
index f6af31448b..fda8a22fa2 100644
--- a/vlib/v/checker/checker.v
+++ b/vlib/v/checker/checker.v
@@ -501,7 +501,8 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
}
}
if !type_sym.is_public && type_sym.kind != .placeholder && type_sym.mod != c.mod &&
- type_sym.language != .c {
+ type_sym.language != .c
+ {
c.error('type `$type_sym.name` is private', struct_init.pos)
}
if type_sym.kind == .struct_ {
@@ -618,7 +619,8 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
}
}
if info_field.typ.is_ptr() && !expr_type.is_ptr() && !expr_type.is_pointer() &&
- !expr_type.is_number() {
+ !expr_type.is_number()
+ {
c.error('ref', field.pos)
}
struct_init.fields[i].typ = expr_type
@@ -770,11 +772,13 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
}
.plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe { // binary operators that expect matching types
if right.info is table.Alias &&
- (right.info as table.Alias).language != .c && c.mod == c.table.type_to_str(right_type).split('.')[0] {
+ (right.info as table.Alias).language != .c && c.mod == c.table.type_to_str(right_type).split('.')[0]
+ {
right = c.table.get_type_symbol((right.info as table.Alias).parent_type)
}
if left.info is table.Alias &&
- (left.info as table.Alias).language != .c && c.mod == c.table.type_to_str(left_type).split('.')[0] {
+ (left.info as table.Alias).language != .c && c.mod == c.table.type_to_str(left_type).split('.')[0]
+ {
left = c.table.get_type_symbol((left.info as table.Alias).parent_type)
}
if left.kind in [.array, .array_fixed, .map, .struct_] {
@@ -879,7 +883,8 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
return table.void_type
}
if right.kind == .array &&
- c.check_types(left_value_type, c.table.value_type(right_type)) {
+ c.check_types(left_value_type, c.table.value_type(right_type))
+ {
// []T << []T
return table.void_type
}
@@ -951,7 +956,8 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
c.error('bool types only have the following operators defined: `==`, `!=`, `||`, and `&&`',
infix_expr.pos)
} else if left_type == table.string_type &&
- infix_expr.op !in [.plus, .eq, .ne, .lt, .gt, .le, .ge] {
+ infix_expr.op !in [.plus, .eq, .ne, .lt, .gt, .le, .ge]
+ {
// TODO broken !in
c.error('string types only have the following operators defined: `==`, `!=`, `<`, `>`, `<=`, `>=`, and `+`',
infix_expr.pos)
@@ -1151,7 +1157,8 @@ pub fn (mut c Checker) call_expr(mut call_expr ast.CallExpr) table.Type {
continue
}
if arg.expr is ast.Ident ||
- arg.expr is ast.StringLiteral || arg.expr is ast.SelectorExpr {
+ arg.expr is ast.StringLiteral || arg.expr is ast.SelectorExpr
+ {
// Simple expressions like variables, string literals, selector expressions
// (`x.field`) can't result in allocations and don't need to be assigned to
// temporary vars.
@@ -1162,7 +1169,8 @@ pub fn (mut c Checker) call_expr(mut call_expr ast.CallExpr) table.Type {
}
// TODO copy pasta from above
if call_expr.receiver_type == table.string_type && !(call_expr.left is ast.Ident ||
- call_expr.left is ast.StringLiteral || call_expr.left is ast.SelectorExpr) {
+ call_expr.left is ast.StringLiteral || call_expr.left is ast.SelectorExpr)
+ {
call_expr.free_receiver = true
}
}
@@ -1185,10 +1193,12 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ table.Type, call_e
if arg_expr.decl.params.len > 1 {
c.error('function needs exactly 1 argument', arg_expr.decl.pos)
} else if is_map &&
- (arg_expr.decl.return_type == table.void_type || arg_expr.decl.params[0].typ != elem_typ) {
+ (arg_expr.decl.return_type == table.void_type || arg_expr.decl.params[0].typ != elem_typ)
+ {
c.error('type mismatch, should use `fn(a $elem_sym.name) T {...}`', arg_expr.decl.pos)
} else if !is_map &&
- (arg_expr.decl.return_type != table.bool_type || arg_expr.decl.params[0].typ != elem_typ) {
+ (arg_expr.decl.return_type != table.bool_type || arg_expr.decl.params[0].typ != elem_typ)
+ {
c.error('type mismatch, should use `fn(a $elem_sym.name) bool {...}`',
arg_expr.decl.pos)
}
@@ -1202,11 +1212,13 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ table.Type, call_e
if func.params.len > 1 {
c.error('function needs exactly 1 argument', call_expr.pos)
} else if is_map &&
- (func.return_type == table.void_type || func.params[0].typ != elem_typ) {
+ (func.return_type == table.void_type || func.params[0].typ != elem_typ)
+ {
c.error('type mismatch, should use `fn(a $elem_sym.name) T {...}`',
arg_expr.pos)
} else if !is_map &&
- (func.return_type != table.bool_type || func.params[0].typ != elem_typ) {
+ (func.return_type != table.bool_type || func.params[0].typ != elem_typ)
+ {
c.error('type mismatch, should use `fn(a $elem_sym.name) bool {...}`',
arg_expr.pos)
}
@@ -1379,7 +1391,8 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
}
if has_method {
if !method.is_pub && !c.is_builtin_mod && !c.pref.is_test && left_type_sym.mod != c.mod &&
- left_type_sym.mod != '' { // method.mod != c.mod {
+ left_type_sym.mod != ''
+ { // method.mod != c.mod {
// If a private method is called outside of the module
// its receiver type is defined in, show an error.
// println('warn $method_name lef.mod=$left_type_sym.mod c.mod=$c.mod')
@@ -1390,7 +1403,8 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
// call_expr.is_mut = true
}
if method.return_type == table.void_type &&
- method.ctdefine.len > 0 && method.ctdefine !in c.pref.compile_defines {
+ method.ctdefine.len > 0 && method.ctdefine !in c.pref.compile_defines
+ {
call_expr.should_be_skipped = true
}
nr_args := if method.params.len == 0 { 0 } else { method.params.len - 1 }
@@ -1677,7 +1691,8 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
c.warn('function `$f.name` has been deprecated', call_expr.pos)
}
if f.is_unsafe && !c.inside_unsafe && f.language == .c && f.name[2] in [`m`, `s`] &&
- f.mod == 'builtin' {
+ f.mod == 'builtin'
+ {
// builtin C.m*, C.s* only - temp
c.warn('function `$f.name` must be called from an `unsafe` block', call_expr.pos)
}
@@ -1709,7 +1724,8 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
call_expr.return_type = f.return_type
}
if f.return_type == table.void_type &&
- f.ctdefine.len > 0 && f.ctdefine !in c.pref.compile_defines {
+ f.ctdefine.len > 0 && f.ctdefine !in c.pref.compile_defines
+ {
call_expr.should_be_skipped = true
}
if f.language != .v || call_expr.language != .v {
@@ -2124,7 +2140,8 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) {
return_stmt.pos)
return
} else if return_stmt.exprs.len == 0 && !(c.expected_type == table.void_type ||
- expected_type_sym.kind == .void) {
+ expected_type_sym.kind == .void)
+ {
c.error('too few arguments to return', return_stmt.pos)
return
}
@@ -2162,7 +2179,8 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) {
for i, exp_type in expected_types {
got_typ := c.unwrap_generic(got_types[i])
if got_typ.has_flag(.optional) &&
- (!exp_type.has_flag(.optional) || c.table.type_to_str(got_typ) != c.table.type_to_str(exp_type)) {
+ (!exp_type.has_flag(.optional) || c.table.type_to_str(got_typ) != c.table.type_to_str(exp_type))
+ {
pos := return_stmt.exprs[i].position()
c.error('cannot use `${c.table.type_to_str(got_typ)}` as type `${c.table.type_to_str(exp_type)}` in return argument',
pos)
@@ -2179,13 +2197,15 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) {
pos)
}
if (got_typ.is_ptr() || got_typ.is_pointer()) &&
- (!exp_type.is_ptr() && !exp_type.is_pointer()) {
+ (!exp_type.is_ptr() && !exp_type.is_pointer())
+ {
pos := return_stmt.exprs[i].position()
c.error('fn `$c.cur_fn.name` expects you to return a non reference type `${c.table.type_to_str(exp_type)}`, but you are returning `${c.table.type_to_str(got_typ)}` instead',
pos)
}
if (exp_type.is_ptr() || exp_type.is_pointer()) &&
- (!got_typ.is_ptr() && !got_typ.is_pointer()) && got_typ != table.int_literal_type {
+ (!got_typ.is_ptr() && !got_typ.is_pointer()) && got_typ != table.int_literal_type
+ {
pos := return_stmt.exprs[i].position()
c.error('fn `$c.cur_fn.name` expects you to return a reference type `${c.table.type_to_str(exp_type)}`, but you are returning `${c.table.type_to_str(got_typ)}` instead',
pos)
@@ -2466,7 +2486,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
}
if left_sym.kind == .array && !c.inside_unsafe && assign_stmt.op in [.assign, .decl_assign] &&
right_sym.kind == .array &&
- (left is ast.Ident && !left.is_blank_ident()) && right is ast.Ident {
+ (left is ast.Ident && !left.is_blank_ident()) && right is ast.Ident
+ {
// Do not allow `a = b`, only `a = b.clone()`
c.error('use `array2 = array1.clone()` instead of `array2 = array1` (or use `unsafe`)',
assign_stmt.pos)
@@ -2524,22 +2545,26 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
}
.mult_assign, .div_assign {
if !left_sym.is_number() &&
- !c.table.get_final_type_symbol(left_type_unwrapped).is_int() && left_sym.kind !in [.struct_, .alias] {
+ !c.table.get_final_type_symbol(left_type_unwrapped).is_int() && left_sym.kind !in [.struct_, .alias]
+ {
c.error('operator $assign_stmt.op.str() not defined on left operand type `$left_sym.name`',
left.position())
} else if !right_sym.is_number() &&
- !c.table.get_final_type_symbol(left_type_unwrapped).is_int() && left_sym.kind !in [.struct_, .alias] {
+ !c.table.get_final_type_symbol(left_type_unwrapped).is_int() && left_sym.kind !in [.struct_, .alias]
+ {
c.error('operator $assign_stmt.op.str() not defined on right operand type `$right_sym.name`',
right.position())
}
}
.and_assign, .or_assign, .xor_assign, .mod_assign, .left_shift_assign, .right_shift_assign {
if !left_sym.is_int() &&
- !c.table.get_final_type_symbol(left_type_unwrapped).is_int() {
+ !c.table.get_final_type_symbol(left_type_unwrapped).is_int()
+ {
c.error('operator $assign_stmt.op.str() not defined on left operand type `$left_sym.name`',
left.position())
} else if !right_sym.is_int() &&
- !c.table.get_final_type_symbol(right_type_unwrapped).is_int() {
+ !c.table.get_final_type_symbol(right_type_unwrapped).is_int()
+ {
c.error('operator $assign_stmt.op.str() not defined on right operand type `$right_sym.name`',
right.position())
}
@@ -2548,7 +2573,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
}
if assign_stmt.op in
[.plus_assign, .minus_assign, .mod_assign, .mult_assign, .div_assign] &&
- ((left_sym.kind == .struct_ && right_sym.kind == .struct_) || left_sym.kind == .alias) {
+ ((left_sym.kind == .struct_ && right_sym.kind == .struct_) || left_sym.kind == .alias)
+ {
left_name := c.table.type_to_str(left_type)
right_name := c.table.type_to_str(right_type)
parent_sym := c.table.get_final_type_symbol(left_type)
@@ -3062,7 +3088,8 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
}
flag_no_comment := flag.all_before('//').trim_space()
if !((flag_no_comment.starts_with('"') && flag_no_comment.ends_with('"')) ||
- (flag_no_comment.starts_with('<') && flag_no_comment.ends_with('>'))) {
+ (flag_no_comment.starts_with('<') && flag_no_comment.ends_with('>')))
+ {
c.error('including C files should use either `"header_file.h"` or `` quoting',
node.pos)
}
@@ -3461,7 +3488,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) table.Type {
}
} else if node.typ == table.string_type &&
(from_type_sym.kind in [.int_literal, .int, .byte, .byteptr, .bool] ||
- (from_type_sym.kind == .array && from_type_sym.name == 'array_byte')) {
+ (from_type_sym.kind == .array && from_type_sym.name == 'array_byte'))
+ {
type_name := c.table.type_to_str(node.expr_type)
c.error('cannot cast type `$type_name` to string, use `x.str()` instead', node.pos)
} else if node.expr_type == table.string_type {
@@ -3476,7 +3504,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) table.Type {
}
} else if to_type_sym.kind == .byte &&
node.expr_type != table.voidptr_type && from_type_sym.kind != .enum_ && !node.expr_type.is_int() &&
- !node.expr_type.is_float() && !node.expr_type.is_ptr() {
+ !node.expr_type.is_float() && !node.expr_type.is_ptr()
+ {
type_name := c.table.type_to_str(node.expr_type)
c.error('cannot cast type `$type_name` to `byte`', node.pos)
} else if to_type_sym.kind == .struct_ && !node.typ.is_ptr() && !(to_type_sym.info as table.Struct).is_typedef {
@@ -4123,7 +4152,8 @@ pub fn (mut c Checker) select_expr(mut node ast.SelectExpr) table.Type {
} else {
if branch.stmt.expr is ast.InfixExpr {
if branch.stmt.expr.left !is ast.Ident &&
- branch.stmt.expr.left !is ast.SelectorExpr && branch.stmt.expr.left !is ast.IndexExpr {
+ branch.stmt.expr.left !is ast.SelectorExpr && branch.stmt.expr.left !is ast.IndexExpr
+ {
c.error('channel in `select` key must be predefined', branch.stmt.expr.left.position())
}
} else {
@@ -4136,7 +4166,8 @@ pub fn (mut c Checker) select_expr(mut node ast.SelectExpr) table.Type {
match expr {
ast.PrefixExpr {
if expr.right !is ast.Ident &&
- expr.right !is ast.SelectorExpr && expr.right !is ast.IndexExpr {
+ expr.right !is ast.SelectorExpr && expr.right !is ast.IndexExpr
+ {
c.error('channel in `select` key must be predefined', expr.right.position())
}
if expr.or_block.kind != .absent {
@@ -4217,7 +4248,8 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) {
if infix.op == .key_is {
if (infix.left is ast.Ident ||
infix.left is ast.SelectorExpr) &&
- infix.right is ast.Type {
+ infix.right is ast.Type
+ {
right_expr := infix.right as ast.Type
is_variable := if mut infix.left is ast.Ident {
infix.left.kind == .variable
@@ -4290,7 +4322,8 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) table.Type {
}
if (infix.left is ast.Ident ||
infix.left is ast.SelectorExpr) &&
- infix.right is ast.Type {
+ infix.right is ast.Type
+ {
is_variable := if mut infix.left is ast.Ident {
infix.left.kind == .variable
} else {
@@ -4487,7 +4520,8 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
.key_is, .not_is {
if (cond.left is ast.SelectorExpr ||
cond.left is ast.Type) &&
- cond.right is ast.Type {
+ cond.right is ast.Type
+ {
// $if method.@type is string
} else {
c.error('invalid `\$if` condition: $cond.left', cond.pos)
@@ -4549,7 +4583,8 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
// `$if some_var {}`
typ := c.expr(cond)
if cond.obj !is ast.Var &&
- cond.obj !is ast.ConstField && cond.obj !is ast.GlobalField {
+ cond.obj !is ast.ConstField && cond.obj !is ast.GlobalField
+ {
c.error('unknown var: `$cond.name`', pos)
return false
}
@@ -4738,7 +4773,8 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) table.Type {
node.left_type = typ
typ_sym := c.table.get_final_type_symbol(typ)
if typ_sym.kind !in [.array, .array_fixed, .string, .map] && !typ.is_ptr() && typ !in [table.byteptr_type, table.charptr_type] &&
- !typ.has_flag(.variadic) {
+ !typ.has_flag(.variadic)
+ {
c.error('type `$typ_sym.name` does not support indexing', node.pos)
}
if typ_sym.kind == .string && !typ.is_ptr() && node.is_setter {
@@ -5153,14 +5189,16 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
for arg in node.params {
sym := c.table.get_type_symbol(arg.typ)
if sym.kind == .placeholder ||
- (sym.kind in [table.Kind.int_literal, .float_literal] && !c.is_builtin_mod) {
+ (sym.kind in [table.Kind.int_literal, .float_literal] && !c.is_builtin_mod)
+ {
c.error('unknown type `$sym.name`', node.pos)
}
}
}
return_sym := c.table.get_type_symbol(node.return_type)
if node.language == .v &&
- return_sym.kind in [.placeholder, .int_literal, .float_literal] && return_sym.language == .v {
+ return_sym.kind in [.placeholder, .int_literal, .float_literal] && return_sym.language == .v
+ {
c.error('unknown type `$return_sym.name`', node.pos)
}
if node.language == .v && node.is_method && node.name == 'str' {
@@ -5172,7 +5210,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
}
}
if node.language == .v && node.is_method && node.name in
- ['+', '-', '*', '%', '/', '<', '>', '==', '!=', '>=', '<='] {
+ ['+', '-', '*', '%', '/', '<', '>', '==', '!=', '>=', '<=']
+ {
if node.params.len != 2 {
c.error('operator methods should have exactly 1 argument', node.pos)
} else {
@@ -5190,7 +5229,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
} else if node.receiver.typ != node.params[1].typ {
c.error('both sides of an operator must be the same type', node.pos)
} else if node.name in ['<', '>', '==', '!=', '>=', '<='] &&
- node.return_type != table.bool_type {
+ node.return_type != table.bool_type
+ {
c.error('operator comparison methods should return `bool`', node.pos)
} else if parent_sym.is_primitive() {
c.error('cannot define operator methods on type alias for `$parent_sym.name`',
@@ -5220,7 +5260,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.cur_fn = node
// Add return if `fn(...) ? {...}` have no return at end
if node.return_type != table.void_type && node.return_type.has_flag(.optional) &&
- (node.stmts.len == 0 || node.stmts[node.stmts.len - 1] !is ast.Return) {
+ (node.stmts.len == 0 || node.stmts[node.stmts.len - 1] !is ast.Return)
+ {
sym := c.table.get_type_symbol(node.return_type)
if sym.kind == .void {
node.stmts << ast.Return{
@@ -5231,7 +5272,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.stmts(node.stmts)
returns := c.returns || has_top_return(node.stmts)
if node.language == .v && !node.no_body && node.return_type != table.void_type && !returns &&
- node.name !in ['panic', 'exit'] {
+ node.name !in ['panic', 'exit']
+ {
c.error('missing return at end of function `$node.name`', node.pos)
}
c.returns = false
@@ -5288,7 +5330,8 @@ fn (mut c Checker) verify_all_vweb_routes() {
continue
}
if f.return_type == typ_vweb_result &&
- f.receiver.typ == m.params[0].typ && f.name == m.name {
+ f.receiver.typ == m.params[0].typ && f.name == m.name
+ {
c.file = f.source_file // setup of file path for the warning
c.warn('mismatched parameters count between vweb method `${sym_app.name}.$m.name` ($nargs) and route attribute $m.attrs ($nroute_attributes)',
f.pos)
diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v
index 8ae39ce69f..bb23c3bb1f 100644
--- a/vlib/v/fmt/fmt.v
+++ b/vlib/v/fmt/fmt.v
@@ -158,7 +158,8 @@ fn (mut f Fmt) adjust_complete_line() {
// search for next position with low penalty and same precedence to form subexpression
for j in i .. f.penalties.len {
if f.penalties[j] <= 1 &&
- f.precedences[j] == precedence && len_sub_expr >= max_len[1] {
+ f.precedences[j] == precedence && len_sub_expr >= max_len[1]
+ {
sub_expr_end_idx = j
break
} else if f.precedences[j] < precedence {
@@ -1555,8 +1556,15 @@ 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 := if cond_len > 0 { '\n' in f.out.last_n(cond_len) } else { false }
+ if is_cond_wrapped {
+ f.writeln('')
+ } else {
+ f.write(' ')
+ }
}
f.write('{')
if single_line {
@@ -1857,11 +1865,13 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
mut penalty := if line_break && !is_same_line_comment { 0 } else { 3 }
if penalty > 0 {
if i == 0 || it.exprs[i - 1] is ast.ArrayInit || it.exprs[i - 1] is ast.StructInit ||
- it.exprs[i - 1] is ast.MapInit || it.exprs[i - 1] is ast.CallExpr {
+ it.exprs[i - 1] is ast.MapInit || it.exprs[i - 1] is ast.CallExpr
+ {
penalty--
}
if expr is ast.ArrayInit ||
- expr is ast.StructInit || expr is ast.MapInit || expr is ast.CallExpr {
+ expr is ast.StructInit || expr is ast.MapInit || expr is ast.CallExpr
+ {
penalty--
}
}
@@ -2021,7 +2031,8 @@ pub fn (mut f Fmt) struct_init(it ast.StructInit) {
f.comments(field.next_comments, inline: false, has_nl: true, level: .keep)
if single_line_fields &&
(field.comments.len > 0 ||
- field.next_comments.len > 0 || !expr_is_single_line(field.expr) || f.line_len > max_len.last()) {
+ field.next_comments.len > 0 || !expr_is_single_line(field.expr) || f.line_len > max_len.last())
+ {
single_line_fields = false
f.out.go_back_to(fields_start)
f.line_len = fields_start
diff --git a/vlib/v/fmt/tests/expressions_expected.vv b/vlib/v/fmt/tests/expressions_expected.vv
index 28507e418c..149bb1b009 100644
--- a/vlib/v/fmt/tests/expressions_expected.vv
+++ b/vlib/v/fmt/tests/expressions_expected.vv
@@ -12,7 +12,8 @@ fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) tabl
mut fmt := node.fmts[i]
// analyze and validate format specifier
if fmt !in
- [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`] {
+ [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`]
+ {
c.error('unknown format specifier `${fmt:c}`', node.fmt_poss[i])
}
if node.precisions[i] != 987698 && !typ.is_float() {
@@ -27,7 +28,8 @@ fn string_inter_lit(mut c checker.Checker, mut node ast.StringInterLiteral) tabl
(typ.is_float() && fmt !in [`E`, `F`, `G`, `e`, `f`, `g`]) ||
(typ.is_pointer() && fmt !in [`p`, `x`, `X`]) ||
(typ.is_string() && fmt != `s`) ||
- (typ.idx() in [table.i64_type_idx, table.f64_type_idx] && fmt == `c`) {
+ (typ.idx() in [table.i64_type_idx, table.f64_type_idx] && fmt == `c`)
+ {
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
node.fmt_poss[i])
}
@@ -54,7 +56,8 @@ fn main() {
' that is followd by an even longer part that should go to another line')
if (a == b && b > r) ||
(d > r) || (a < b) || (b < d && a + b > r) ||
- (a + b + d >= 0 && r < 0) || (a > b && d - r < b) {
+ (a + b + d >= 0 && r < 0) || (a > b && d - r < b)
+ {
println('ok')
}
}
@@ -73,7 +76,8 @@ struct Parser {
fn (mut p Parser) name_expr() {
if p.peek_tok.kind == .lpar ||
- (p.peek_tok.kind == .lt && p.peek_tok2.kind == .name && p.peek_tok3.kind == .gt) {
+ (p.peek_tok.kind == .lt && p.peek_tok2.kind == .name && p.peek_tok3.kind == .gt)
+ {
println(p.peek_tok.lit)
}
}
diff --git a/vlib/v/fmt/tests/select_keep.vv b/vlib/v/fmt/tests/select_keep.vv
index 3b44fa4328..b901ae9819 100644
--- a/vlib/v/fmt/tests/select_keep.vv
+++ b/vlib/v/fmt/tests/select_keep.vv
@@ -108,7 +108,8 @@ fn test_select_blocks() {
else {
h = 2
}
- } {
+ }
+ {
panic('channel is still open')
} else {
is_open = false
diff --git a/vlib/v/gen/auto_str_methods.v b/vlib/v/gen/auto_str_methods.v
index b1315b885c..4ea3defc18 100644
--- a/vlib/v/gen/auto_str_methods.v
+++ b/vlib/v/gen/auto_str_methods.v
@@ -41,7 +41,8 @@ fn (g &Gen) type_to_fmt(typ table.Type) string {
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] {
+ [.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/cgen.v b/vlib/v/gen/cgen.v
index f4fadcabe7..5e0a135acb 100644
--- a/vlib/v/gen/cgen.v
+++ b/vlib/v/gen/cgen.v
@@ -989,7 +989,8 @@ fn (mut g Gen) stmt(node ast.Stmt) {
mod := if g.is_builtin_mod { 'builtin' } else { node.name.all_before_last('.') }
if (mod != g.module_built &&
node.mod != g.module_built.after('/')) ||
- should_bundle_module {
+ should_bundle_module
+ {
// Skip functions that don't have to be generated for this module.
// println('skip bm $node.name mod=$node.mod module_built=$g.module_built')
skip = true
@@ -1014,12 +1015,14 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.has_main = true
}
if node.name == 'backtrace' ||
- node.name == 'backtrace_symbols' || node.name == 'backtrace_symbols_fd' {
+ node.name == 'backtrace_symbols' || node.name == 'backtrace_symbols_fd'
+ {
g.write('\n#ifndef __cplusplus\n')
}
g.gen_fn_decl(node, skip)
if node.name == 'backtrace' ||
- node.name == 'backtrace_symbols' || node.name == 'backtrace_symbols_fd' {
+ node.name == 'backtrace_symbols' || node.name == 'backtrace_symbols_fd'
+ {
g.write('\n#endif\n')
}
g.fn_decl = keep_fn_decl
@@ -1963,7 +1966,8 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
if ((left_sym.kind == .struct_ &&
right_sym.kind == .struct_) || (left_sym.kind == .alias &&
right_sym.kind == .alias)) &&
- assign_stmt.op in [.plus_assign, .minus_assign, .div_assign, .mult_assign, .mod_assign] {
+ assign_stmt.op in [.plus_assign, .minus_assign, .div_assign, .mult_assign, .mod_assign]
+ {
extracted_op := match assign_stmt.op {
.plus_assign { '+' }
.minus_assign { '-' }
@@ -2296,7 +2300,8 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
// ```
// if !isnil(scope.parent) && line_nr > 0 {
if free_parent_scopes && !isnil(scope.parent) &&
- (stop_pos == -1 || scope.parent.start_pos >= stop_pos) {
+ (stop_pos == -1 || scope.parent.start_pos >= stop_pos)
+ {
g.writeln('// af parent scope:')
g.autofree_scope_vars2(scope.parent, start_pos, end_pos, line_nr, true, stop_pos)
}
@@ -2455,7 +2460,8 @@ fn (mut g Gen) expr(node ast.Expr) {
// println('before:' + node.autofree_pregen)
// }
if g.is_autofree && !g.is_builtin_mod && !g.is_js_call && g.strs_to_free0.len == 0 &&
- !g.inside_lambda { // && g.inside_ternary ==
+ !g.inside_lambda
+ { // && g.inside_ternary ==
// if len != 0, that means we are handling call expr inside call expr (arg)
// and it'll get messed up here, since it's handled recursively in autofree_call_pregen()
// so just skip it
@@ -2522,13 +2528,15 @@ fn (mut g Gen) expr(node ast.Expr) {
mut cast_label := ''
// `table.string_type` is done for MSVC's bug
if sym.kind != .alias ||
- (sym.info as table.Alias).parent_type !in [node.expr_type, table.string_type] {
+ (sym.info as table.Alias).parent_type !in [node.expr_type, table.string_type]
+ {
cast_label = '($styp)'
}
g.write('(${cast_label}(')
g.expr(node.expr)
if node.expr is ast.IntegerLiteral &&
- node.typ in [table.u64_type, table.u32_type, table.u16_type] {
+ node.typ in [table.u64_type, table.u32_type, table.u16_type]
+ {
g.write('U')
}
g.write('))')
@@ -2995,7 +3003,8 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
} else if unaliased_left == table.string_type_idx && node.op !in [.key_in, .not_in] {
// `str == ''` -> `str.len == 0` optimization
if node.op in [.eq, .ne] &&
- node.right is ast.StringLiteral && (node.right as ast.StringLiteral).val == '' {
+ node.right is ast.StringLiteral && (node.right as ast.StringLiteral).val == ''
+ {
arrow := if left_type.is_ptr() { '->' } else { '.' }
g.write('(')
g.expr(node.left)
@@ -3052,7 +3061,8 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.expr(node.right)
g.write(')')
} else if node.op in [.eq, .ne] &&
- left_sym.kind == .array_fixed && right_sym.kind == .array_fixed {
+ left_sym.kind == .array_fixed && right_sym.kind == .array_fixed
+ {
ptr_typ := g.gen_fixed_array_equality_fn(left_type)
if node.op == .ne {
g.write('!')
@@ -3091,7 +3101,8 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.expr(node.right)
g.write(')')
} else if node.op in [.eq, .ne] &&
- left_sym.kind == .struct_ && right_sym.kind == .struct_ && has_eq_overloaded && has_ne_overloaded {
+ left_sym.kind == .struct_ && right_sym.kind == .struct_ && has_eq_overloaded && has_ne_overloaded
+ {
ptr_typ := g.gen_struct_equality_fn(left_type)
if node.op == .eq {
g.write('${ptr_typ}_struct_eq(')
@@ -3233,18 +3244,22 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.or_block(tmp_opt, node.or_block, table.void_type)
}
} else if unaliased_left.idx() in [table.u32_type_idx, table.u64_type_idx] && unaliased_right.is_signed() &&
- node.op in [.eq, .ne, .gt, .lt, .ge, .le] {
+ node.op in [.eq, .ne, .gt, .lt, .ge, .le]
+ {
bitsize := if unaliased_left.idx() == table.u32_type_idx &&
- unaliased_right.idx() != table.i64_type_idx { 32 } else { 64 }
+ unaliased_right.idx() != table.i64_type_idx
+ { 32 } else { 64 }
g.write('_us${bitsize}_${cmp_str[int(node.op) - int(token.Kind.eq)]}(')
g.expr(node.left)
g.write(',')
g.expr(node.right)
g.write(')')
} else if unaliased_right.idx() in [table.u32_type_idx, table.u64_type_idx] && unaliased_left.is_signed() &&
- node.op in [.eq, .ne, .gt, .lt, .ge, .le] {
+ node.op in [.eq, .ne, .gt, .lt, .ge, .le]
+ {
bitsize := if unaliased_right.idx() == table.u32_type_idx &&
- unaliased_left.idx() != table.i64_type_idx { 32 } else { 64 }
+ unaliased_left.idx() != table.i64_type_idx
+ { 32 } else { 64 }
g.write('_us${bitsize}_${cmp_rev[int(node.op) - int(token.Kind.eq)]}(')
g.expr(node.right)
g.write(',')
@@ -3261,7 +3276,8 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
// Do not generate operator overloading with these `right_sym.kind`.
e := right_sym.kind !in [.voidptr, .int_literal, .int]
if node.op in [.plus, .minus, .mul, .div, .mod, .lt, .gt, .eq, .ne, .le, .ge] &&
- ((a && b && e) || c || d) {
+ ((a && b && e) || c || d)
+ {
// Overloaded operators
g.write(g.typ(if !d {
left_type
@@ -3466,7 +3482,8 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
mut skip_low := false
if expr.low is ast.IntegerLiteral {
if node.cond_type in [table.u16_type, table.u32_type, table.u64_type] &&
- expr.low.val == '0' {
+ expr.low.val == '0'
+ {
skip_low = true
}
}
@@ -3533,7 +3550,8 @@ fn (mut g Gen) select_expr(node ast.SelectExpr) {
expr := branch.stmt.expr as ast.InfixExpr
channels << expr.left
if expr.right is ast.Ident ||
- expr.right is ast.IndexExpr || expr.right is ast.SelectorExpr || expr.right is ast.StructInit {
+ expr.right is ast.IndexExpr || expr.right is ast.SelectorExpr || expr.right is ast.StructInit
+ {
// addressable objects in the `C` output
objs << expr.right
tmp_objs << ''
@@ -3554,7 +3572,8 @@ fn (mut g Gen) select_expr(node ast.SelectExpr) {
is_push << false
// create tmp unless the object with *exactly* the type we need exists already
if branch.stmt.op == .decl_assign ||
- branch.stmt.right_types[0] != branch.stmt.left_types[0] {
+ branch.stmt.right_types[0] != branch.stmt.left_types[0]
+ {
tmp_obj := g.new_tmp_var()
tmp_objs << tmp_obj
el_stype := g.typ(branch.stmt.right_types[0])
@@ -4078,7 +4097,8 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
g.write('$zero }))')
}
} else if (g.inside_map_postfix || g.inside_map_infix) ||
- (g.is_assign_lhs && !g.is_array_set && get_and_set_types) {
+ (g.is_assign_lhs && !g.is_array_set && get_and_set_types)
+ {
zero := g.type_default(info.value_type)
g.write('(*($elem_type_str*)map_get_and_set_1(')
if !left_is_ptr {
@@ -4543,7 +4563,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
}
if !cloned {
if field.expected_type.is_ptr() && !(field.typ.is_ptr() || field.typ.is_pointer()) &&
- !field.typ.is_number() {
+ !field.typ.is_number()
+ {
g.write('/* autoref */&')
}
g.expr_with_cast(field.expr, field.typ, field.expected_type)
@@ -4615,7 +4636,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
g.interface_call(sfield.typ, sfield.expected_type)
}
if sfield.expected_type.is_ptr() && !(sfield.typ.is_ptr() || sfield.typ.is_pointer()) &&
- !sfield.typ.is_number() {
+ !sfield.typ.is_number()
+ {
g.write('/* autoref */&')
}
g.expr_with_cast(sfield.expr, sfield.typ, sfield.expected_type)
@@ -5066,7 +5088,8 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
}
stmts := or_block.stmts
if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt && (stmts[stmts.len -
- 1] as ast.ExprStmt).typ != table.void_type {
+ 1] as ast.ExprStmt).typ != table.void_type
+ {
g.indent++
for i, stmt in stmts {
if i == stmts.len - 1 {
@@ -5279,7 +5302,8 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string
}
else {
if is_comptime_optional ||
- (g.pref.compile_defines_all.len > 0 && name in g.pref.compile_defines_all) {
+ (g.pref.compile_defines_all.len > 0 && name in g.pref.compile_defines_all)
+ {
return 'CUSTOM_DEFINE_$name'
}
return error('bad os ifdef name "$name"') // should never happen, caught in the checker
diff --git a/vlib/v/gen/comptime.v b/vlib/v/gen/comptime.v
index 7590190f02..e2e0a6ee19 100644
--- a/vlib/v/gen/comptime.v
+++ b/vlib/v/gen/comptime.v
@@ -18,7 +18,8 @@ fn (mut g Gen) comptime_selector(node ast.ComptimeSelector) {
if node.field_expr is ast.SelectorExpr {
if node.field_expr.expr is ast.Ident {
if node.field_expr.expr.name == g.comp_for_field_var &&
- node.field_expr.field_name == 'name' {
+ node.field_expr.field_name == 'name'
+ {
g.write(g.comp_for_field_value.name)
return
}
diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v
index db42e000aa..581c0639e2 100644
--- a/vlib/v/gen/fn.v
+++ b/vlib/v/gen/fn.v
@@ -127,7 +127,8 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
fargs, fargtypes := g.fn_args(it.params, it.is_variadic)
arg_str := g.out.after(arg_start_pos)
if it.no_body ||
- ((g.pref.use_cache && g.pref.build_mode != .build_module) && it.is_builtin) || skip {
+ ((g.pref.use_cache && g.pref.build_mode != .build_module) && it.is_builtin) || skip
+ {
// Just a function header. Builtin function bodies are defined in builtin.o
g.definitions.writeln(');') // // NO BODY')
g.writeln(');')
@@ -297,7 +298,8 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
}
if node.is_method && !node.is_field {
if node.name == 'writeln' && g.pref.experimental && node.args.len > 0 && node.args[0].expr is
- ast.StringInterLiteral && g.table.get_type_symbol(node.receiver_type).name == 'strings.Builder' {
+ ast.StringInterLiteral && g.table.get_type_symbol(node.receiver_type).name == 'strings.Builder'
+ {
g.string_inter_literal_sb_optimized(node)
} else {
g.method_call(node)
@@ -408,7 +410,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
}
// TODO performance, detect `array` method differently
if left_sym.kind == .array && node.name in
- ['repeat', 'sort_with_compare', 'free', 'push_many', 'trim', 'first', 'last', 'pop', 'clone', 'reverse', 'slice'] {
+ ['repeat', 'sort_with_compare', 'free', 'push_many', 'trim', 'first', 'last', 'pop', 'clone', 'reverse', 'slice']
+ {
// && rec_sym.name == 'array' {
// && rec_sym.name == 'array' && receiver_name.starts_with('array') {
// `array_byte_clone` => `array_clone`
@@ -469,7 +472,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
g.write('&')
}
} else if !node.receiver_type.is_ptr() && node.left_type.is_ptr() && node.name != 'str' &&
- node.from_embed_type == 0 {
+ node.from_embed_type == 0
+ {
g.write('/*rec*/*')
}
if g.is_autofree && node.free_receiver && !g.inside_lambda && !g.is_builtin_mod {
diff --git a/vlib/v/gen/str.v b/vlib/v/gen/str.v
index e39c971948..73215c68af 100644
--- a/vlib/v/gen/str.v
+++ b/vlib/v/gen/str.v
@@ -341,7 +341,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype table.Type) {
g.write('")')
}
} else if sym_has_str_method || sym.kind in
- [.array, .array_fixed, .map, .struct_, .multi_return, .sum_type, .interface_] {
+ [.array, .array_fixed, .map, .struct_, .multi_return, .sum_type, .interface_]
+ {
is_ptr := typ.is_ptr()
str_fn_name := g.gen_str_for_type(typ)
if is_ptr {
diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v
index e8158ad1f6..d5b41a119f 100644
--- a/vlib/v/parser/fn.v
+++ b/vlib/v/parser/fn.v
@@ -278,7 +278,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
}
}
if p.tok.kind in [.plus, .minus, .mul, .div, .mod, .gt, .lt, .eq, .ne, .le, .ge] &&
- p.peek_tok.kind == .lpar {
+ p.peek_tok.kind == .lpar
+ {
name = p.tok.kind.str() // op_to_fn_name()
if rec_type == table.void_type {
p.error_with_pos('cannot use operator overloading with normal functions',
@@ -318,7 +319,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
// Return type
mut return_type := table.void_type
if p.tok.kind.is_start_of_type() ||
- (p.tok.kind == .key_fn && p.tok.line_nr == p.prev_tok.line_nr) {
+ (p.tok.kind == .key_fn && p.tok.line_nr == p.prev_tok.line_nr)
+ {
return_type = p.parse_type()
}
mut type_sym_method_idx := 0
@@ -687,7 +689,8 @@ fn (mut p Parser) fn_args() ([]table.Param, bool, bool) {
fn (mut p Parser) check_fn_mutable_arguments(typ table.Type, pos token.Position) {
sym := p.table.get_type_symbol(typ)
if sym.kind !in [.array, .array_fixed, .struct_, .map, .placeholder, .sum_type] &&
- !typ.is_ptr() && !typ.is_pointer() {
+ !typ.is_ptr() && !typ.is_pointer()
+ {
p.error_with_pos('mutable arguments are only allowed for arrays, maps, structs and pointers\n' +
'return values instead: `fn foo(mut n $sym.name) {` => `fn foo(n $sym.name) $sym.name {`',
pos)
diff --git a/vlib/v/parser/for.v b/vlib/v/parser/for.v
index 33ba8cb76e..e2e0bdf43f 100644
--- a/vlib/v/parser/for.v
+++ b/vlib/v/parser/for.v
@@ -79,7 +79,8 @@ fn (mut p Parser) for_stmt() ast.Stmt {
p.close_scope()
return for_c_stmt
} else if p.peek_tok.kind in [.key_in, .comma] ||
- (p.tok.kind == .key_mut && p.peek_tok2.kind in [.key_in, .comma]) {
+ (p.tok.kind == .key_mut && p.peek_tok2.kind in [.key_in, .comma])
+ {
// `for i in vals`, `for i in start .. end`, `for mut user in users`, `for i, mut user in users`
mut val_is_mut := p.tok.kind == .key_mut
if val_is_mut {
diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v
index 3515134317..97f137d993 100644
--- a/vlib/v/parser/if_match.v
+++ b/vlib/v/parser/if_match.v
@@ -178,7 +178,8 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
} else if (p.tok.kind == .name && !(p.tok.lit == 'C' &&
p.peek_tok.kind == .dot) && (p.tok.lit in table.builtin_type_names || p.tok.lit[0].is_capital() ||
(p.peek_tok.kind == .dot && p.peek_tok2.lit.len > 0 && p.peek_tok2.lit[0].is_capital()))) ||
- p.tok.kind == .lsbr {
+ p.tok.kind == .lsbr
+ {
mut types := []table.Type{}
for {
// Sum type match
diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v
index df41952a38..95d37b8ac7 100644
--- a/vlib/v/parser/parse_type.v
+++ b/vlib/v/parser/parse_type.v
@@ -53,7 +53,8 @@ pub fn (mut p Parser) parse_map_type() table.Type {
return 0
}
if !(key_type in [table.string_type_idx, table.voidptr_type_idx] ||
- (key_type.is_int() && !key_type.is_ptr())) {
+ (key_type.is_int() && !key_type.is_ptr()))
+ {
s := p.table.type_to_str(key_type)
p.error_with_pos('maps only support string, integer, rune or voidptr keys for now (not `$s`)',
p.tok.position())
diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v
index 1b44ae2104..2e79e1563a 100644
--- a/vlib/v/parser/parser.v
+++ b/vlib/v/parser/parser.v
@@ -128,7 +128,8 @@ pub fn (mut p Parser) set_path(path string) {
if path.ends_with('_c.v') || path.ends_with('.c.v') || path.ends_with('.c.vv') || path.ends_with('.c.vsh') {
p.file_backend_mode = .c
} else if path.ends_with('_js.v') || path.ends_with('.js.v') || path.ends_with('.js.vv') ||
- path.ends_with('.js.vsh') {
+ path.ends_with('.js.vsh')
+ {
p.file_backend_mode = .js
} else {
p.file_backend_mode = .v
@@ -673,7 +674,8 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
p.error_with_pos('unexpected name `$p.peek_tok.lit`', p.peek_tok.position())
return ast.Stmt{}
} else if !p.inside_if_expr && !p.inside_match_body && !p.inside_or_expr &&
- p.peek_tok.kind in [.rcbr, .eof] && !p.mark_var_as_used(p.tok.lit) {
+ p.peek_tok.kind in [.rcbr, .eof] && !p.mark_var_as_used(p.tok.lit)
+ {
p.error_with_pos('`$p.tok.lit` evaluated but not used', p.tok.position())
return ast.Stmt{}
}
@@ -992,7 +994,8 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
} else if tok.kind !in [.key_if, .key_match, .key_lock, .key_rlock, .key_select] &&
left0 !is ast.CallExpr && (is_top_level || p.tok.kind != .rcbr) && left0 !is ast.PostfixExpr &&
!(left0 is ast.InfixExpr && (left0 as ast.InfixExpr).op in [.left_shift, .arrow]) && left0 !is
- ast.ComptimeCall && left0 !is ast.SelectorExpr {
+ ast.ComptimeCall && left0 !is ast.SelectorExpr
+ {
p.error_with_pos('expression evaluated but not used', left0.position())
return ast.Stmt{}
}
@@ -1189,7 +1192,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
known_var := p.mark_var_as_used(p.tok.lit)
mut is_mod_cast := false
if p.peek_tok.kind == .dot && !known_var &&
- (language != .v || p.known_import(p.tok.lit) || p.mod.all_after_last('.') == p.tok.lit) {
+ (language != .v || p.known_import(p.tok.lit) || p.mod.all_after_last('.') == p.tok.lit)
+ {
// p.tok.lit has been recognized as a module
if language == .c {
mod = 'C'
@@ -1200,10 +1204,12 @@ pub fn (mut p Parser) name_expr() ast.Expr {
// mark the imported module as used
p.register_used_import(p.tok.lit)
if p.peek_tok.kind == .dot &&
- p.peek_tok2.kind != .eof && p.peek_tok2.lit.len > 0 && p.peek_tok2.lit[0].is_capital() {
+ p.peek_tok2.kind != .eof && p.peek_tok2.lit.len > 0 && p.peek_tok2.lit[0].is_capital()
+ {
is_mod_cast = true
} else if p.peek_tok.kind == .dot &&
- p.peek_tok2.kind != .eof && p.peek_tok2.lit.len == 0 {
+ p.peek_tok2.kind != .eof && p.peek_tok2.lit.len == 0
+ {
// incomplete module selector must be handled by dot_expr instead
node = p.parse_ident(language)
return node
@@ -1237,7 +1243,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
// if name in table.builtin_type_names {
if (!known_var && (name in p.table.type_idxs ||
name_w_mod in p.table.type_idxs) && name !in ['C.stat', 'C.sigaction']) ||
- is_mod_cast || (language == .v && name[0].is_capital()) {
+ is_mod_cast || (language == .v && name[0].is_capital())
+ {
// MainLetter(x) is *always* a cast, as long as it is not `C.`
// TODO handle C.stat()
start_pos := p.tok.position()
@@ -1281,7 +1288,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
(p.peek_tok.kind == .lt && lit0_is_capital)) &&
(!p.inside_match || (p.inside_select && prev_tok_kind == .arrow && lit0_is_capital)) && !p.inside_match_case &&
(!p.inside_if || p.inside_select) &&
- (!p.inside_for || p.inside_select) { // && (p.tok.lit[0].is_capital() || p.builtin_mod) {
+ (!p.inside_for || p.inside_select)
+ { // && (p.tok.lit[0].is_capital() || p.builtin_mod) {
return p.struct_init(false) // short_syntax: false
} else if p.peek_tok.kind == .dot && (lit0_is_capital && !known_var && language == .v) {
// T.name
@@ -2004,7 +2012,8 @@ const (
fn (mut p Parser) global_decl() ast.GlobalDecl {
if !p.pref.translated && !p.pref.is_livemain && !p.builtin_mod && !p.pref.building_v &&
p.mod != 'ui' && p.mod != 'gg2' && p.mod != 'uiold' && !p.pref.enable_globals && !p.pref.is_fmt &&
- p.mod !in global_enabled_mods {
+ p.mod !in global_enabled_mods
+ {
p.error('use `v --enable-globals ...` to enable globals')
return ast.GlobalDecl{}
}
diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v
index eb1821c917..4c0ec7ab69 100644
--- a/vlib/v/parser/pratt.v
+++ b/vlib/v/parser/pratt.v
@@ -380,7 +380,8 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
right = p.expr(precedence)
p.expecting_type = prev_expecting_type
if p.pref.is_vet && op in [.key_in, .not_in] && right is ast.ArrayInit && (right as ast.ArrayInit).exprs.len ==
- 1 {
+ 1
+ {
p.vet_error('Use `var == value` instead of `var in [value]`', pos.line_nr, vet.FixKind.vfmt)
}
mut or_stmts := []ast.Stmt{}
diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v
index e693c25d65..f080a74108 100644
--- a/vlib/v/parser/struct.v
+++ b/vlib/v/parser/struct.v
@@ -66,7 +66,8 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
return ast.StructDecl{}
}
if language == .v &&
- p.mod != 'builtin' && name.len > 0 && !name[0].is_capital() && !p.pref.translated {
+ p.mod != 'builtin' && name.len > 0 && !name[0].is_capital() && !p.pref.translated
+ {
p.error_with_pos('struct name `$name` must begin with capital letter', name_pos)
return ast.StructDecl{}
}
diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v
index c49f2e6fd4..be9adea590 100644
--- a/vlib/v/pref/pref.v
+++ b/vlib/v/pref/pref.v
@@ -482,7 +482,8 @@ pub fn parse_args(args []string) (&Preferences, string) {
}
must_exist(res.path)
if !res.path.ends_with('.v') && os.is_executable(res.path) && os.is_file(res.path) &&
- os.is_file(res.path + '.v') {
+ os.is_file(res.path + '.v')
+ {
eprintln('It looks like you wanted to run "${res.path}.v", so we went ahead and did that since "$res.path" is an executable.')
res.path += '.v'
}
diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v
index 68de0b93ce..baef1e285f 100644
--- a/vlib/v/scanner/scanner.v
+++ b/vlib/v/scanner/scanner.v
@@ -884,11 +884,13 @@ fn (mut s Scanner) text_scan() token.Token {
s.pos++
return s.new_token(.ne, '', 2)
} else if s.text.len > s.pos + 3 &&
- nextc == `i` && s.text[s.pos + 2] == `n` && s.text[s.pos + 3].is_space() {
+ nextc == `i` && s.text[s.pos + 2] == `n` && s.text[s.pos + 3].is_space()
+ {
s.pos += 2
return s.new_token(.not_in, '', 3)
} else if s.text.len > s.pos + 3 &&
- nextc == `i` && s.text[s.pos + 2] == `s` && s.text[s.pos + 3].is_space() {
+ nextc == `i` && s.text[s.pos + 2] == `s` && s.text[s.pos + 3].is_space()
+ {
s.pos += 2
return s.new_token(.not_is, '', 3)
} else {
@@ -1016,7 +1018,8 @@ fn (mut s Scanner) ident_string() string {
mut n_cr_chars := 0
mut start := s.pos
if s.text[start] == s.quote ||
- (s.text[start] == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter)) {
+ (s.text[start] == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter))
+ {
start++
}
s.is_inside_string = false
@@ -1046,7 +1049,8 @@ fn (mut s Scanner) ident_string() string {
// Don't allow \0
if c == `0` && s.pos > 2 && prevc == slash {
if (s.pos < s.text.len - 1 && s.text[s.pos + 1].is_digit()) ||
- s.count_symbol_before(s.pos - 1, slash) % 2 == 0 {
+ s.count_symbol_before(s.pos - 1, slash) % 2 == 0
+ {
} else if !is_cstr && !is_raw {
s.error(r'cannot use `\0` (NULL character) in the string literal')
}
@@ -1068,7 +1072,8 @@ fn (mut s Scanner) ident_string() string {
if c == `u` && (s.text[s.pos + 1] == s.quote ||
s.text[s.pos + 2] == s.quote || s.text[s.pos + 3] == s.quote || s.text[s.pos + 4] == s.quote ||
!s.text[s.pos + 1].is_hex_digit() || !s.text[s.pos + 2].is_hex_digit() || !s.text[s.pos + 3].is_hex_digit() ||
- !s.text[s.pos + 4].is_hex_digit()) {
+ !s.text[s.pos + 4].is_hex_digit())
+ {
s.error(r'`\u` incomplete unicode character value')
}
}
@@ -1082,7 +1087,8 @@ fn (mut s Scanner) ident_string() string {
}
// $var
if prevc == `$` && util.is_name_char(c) && !is_raw && s.count_symbol_before(s.pos - 2, slash) %
- 2 == 0 {
+ 2 == 0
+ {
s.is_inside_string = true
s.is_inter_start = true
s.pos -= 2
diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v
index 5264c8cdb2..ecc9a49f85 100644
--- a/vlib/vweb/vweb.v
+++ b/vlib/vweb/vweb.v
@@ -424,7 +424,8 @@ fn handle_conn(mut conn net.TcpConn, mut app T) {
// should be called first.
if (req_method_str == '' &&
url_words[0] == method.name && url_words.len == 1) ||
- (req_method_str == req.method.str() && url_words[0] == method.name && url_words.len == 1) {
+ (req_method_str == req.method.str() && url_words[0] == method.name && url_words.len == 1)
+ {
$if debug {
println('easy match method=$method.name')
}
@@ -449,7 +450,8 @@ fn handle_conn(mut conn net.TcpConn, mut app T) {
req_method << route_words[0]
}
if url_words.len == route_words.len ||
- (url_words.len >= route_words.len - 1 && route_words.len > 0 && route_words.last().ends_with('...')) {
+ (url_words.len >= route_words.len - 1 && route_words.len > 0 && route_words.last().ends_with('...'))
+ {
if req_method.len > 0 {
if req_method_str.to_lower()[1..] !in req_method {
continue
diff --git a/vlib/x/websocket/handshake.v b/vlib/x/websocket/handshake.v
index 0ec28d9392..13c9b3a591 100644
--- a/vlib/x/websocket/handshake.v
+++ b/vlib/x/websocket/handshake.v
@@ -119,7 +119,8 @@ fn (mut ws Client) read_handshake_str() ?string {
msg[total_bytes_read] = buffer[0]
total_bytes_read++
if total_bytes_read > 5 && msg[total_bytes_read - 1] == `\n` && msg[total_bytes_read -
- 2] == `\r` && msg[total_bytes_read - 3] == `\n` && msg[total_bytes_read - 4] == `\r` {
+ 2] == `\r` && msg[total_bytes_read - 3] == `\n` && msg[total_bytes_read - 4] == `\r`
+ {
break
}
}
diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v
index 8831610533..2e3a6cc054 100644
--- a/vlib/x/websocket/message.v
+++ b/vlib/x/websocket/message.v
@@ -43,7 +43,8 @@ pub fn (mut ws Client) validate_frame(frame &Frame) ? {
return error('rsv cannot be other than 0, not negotiated')
}
if (int(frame.opcode) >= 3 && int(frame.opcode) <= 7) ||
- (int(frame.opcode) >= 11 && int(frame.opcode) <= 15) {
+ (int(frame.opcode) >= 11 && int(frame.opcode) <= 15)
+ {
ws.close(1002, 'use of reserved opcode') ?
return error('use of reserved opcode')
}