From 80538516b34a0d2a254b56b1d306e6f3af9187c4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 22:06:41 +0300 Subject: [PATCH] all: super_batch5 fixes --- cmd/tools/vdoc/document/module.v | 18 ++++---- cmd/tools/vtest_test.v | 3 +- vlib/builtin/utf8.c.v | 1 + vlib/crypto/argon2/argon2.v | 45 +++++++++---------- vlib/flag/flag.v | 40 +++++++++++++---- vlib/net/ssl/ssl_notd_use_openssl.v | 4 +- vlib/orm/orm_fn_test.v | 3 +- vlib/picoev/picoev.v | 4 +- vlib/picoev/socket_util.c.v | 4 +- vlib/toml/toml.v | 2 +- vlib/v/ast/str.v | 7 ++- vlib/v/ast/table.v | 18 +++++--- vlib/v/ast/types.v | 8 ++++ vlib/v/builder/compile.v | 2 +- vlib/v/checker/checker.v | 9 ++-- vlib/v/checker/comptime.v | 3 +- vlib/v/checker/visible_mutation.v | 4 +- vlib/v/compiler_errors_test.v | 4 +- vlib/v/gen/c/assert.v | 6 +-- vlib/v/gen/c/assign.v | 3 ++ vlib/v/gen/c/cgen.v | 1 + vlib/v/gen/c/defer.v | 5 +++ vlib/v/gen/c/for.v | 16 +++++++ vlib/v/gen/c/infix.v | 3 +- vlib/v/gen/c/labelled_continue_scope_test.v | 3 +- vlib/v/gen/c/sql_assert_temp_var_test.v | 3 +- vlib/v/parser/struct.v | 1 + vlib/v/pref/pref_test.v | 7 ++- vlib/v/tests/failing_tests_test.v | 3 +- ...ultiline_fn_signature_omitted_comma_test.v | 3 +- vlib/v/tests/local_module_submodules_test.v | 6 ++- vlib/v/util/util_test.v | 6 +-- 32 files changed, 157 insertions(+), 88 deletions(-) diff --git a/cmd/tools/vdoc/document/module.v b/cmd/tools/vdoc/document/module.v index 43df2162b..8deef44da 100644 --- a/cmd/tools/vdoc/document/module.v +++ b/cmd/tools/vdoc/document/module.v @@ -17,26 +17,26 @@ fn get_parent_mod(input_dir string) !string { if input_dir == '' { return error('no input folder') } - current_dir := if os.is_dir(input_dir) { input_dir } else { os.dir(input_dir) } // windows root path is C: or D: - if current_dir.len == 2 && current_dir[1] == `:` { + if input_dir.len == 2 && input_dir[1] == `:` { return error('root folder reached') } // unix systems have / at the top: - if current_dir == '/' { + if input_dir == '/' { return error('root folder reached') } - input_dir_name := os.file_name(current_dir) + base_dir := os.dir(input_dir) + input_dir_name := os.file_name(base_dir) prefs := new_vdoc_preferences() - fentries := os.ls(current_dir) or { []string{} } - files := fentries.filter(!os.is_dir(os.join_path(current_dir, it))) + fentries := os.ls(base_dir) or { []string{} } + files := fentries.filter(!os.is_dir(os.join_path(base_dir, it))) if 'v.mod' in files { // the top level is reached, no point in climbing up further return '' } - v_files := prefs.should_compile_filtered_files(current_dir, files) + v_files := prefs.should_compile_filtered_files(base_dir, files) if v_files.len == 0 { - parent_mod := get_parent_mod(os.dir(current_dir)) or { return input_dir_name } + parent_mod := get_parent_mod(base_dir) or { return input_dir_name } if parent_mod.len > 0 { return parent_mod + '.' + input_dir_name } @@ -47,7 +47,7 @@ fn get_parent_mod(input_dir string) !string { if file_ast.mod.short_name == 'main' { return '' } - parent_mod := get_parent_mod(os.dir(current_dir)) or { return input_dir_name } + parent_mod := get_parent_mod(base_dir) or { return input_dir_name } if parent_mod.len > 0 { return '${parent_mod}.${file_ast.mod.short_name}' } diff --git a/cmd/tools/vtest_test.v b/cmd/tools/vtest_test.v index 643130603..c6674a100 100644 --- a/cmd/tools/vtest_test.v +++ b/cmd/tools/vtest_test.v @@ -94,7 +94,8 @@ fn test_partial_failure() { } fn test_wimpure_v_warnings_are_shown_for_test_files() { - res := os.execute_or_exit('${os.quoted_path(mytest_exe)} -Wimpure-v test ${os.quoted_path(tpath_impure)}') + res := + os.execute_or_exit('${os.quoted_path(mytest_exe)} -Wimpure-v test ${os.quoted_path(tpath_impure)}') assert res.output.contains('warning_test.v'), res.output assert res.output.contains('warning: C code will not be allowed in pure .v files'), res.output } diff --git a/vlib/builtin/utf8.c.v b/vlib/builtin/utf8.c.v index 1ee573632..feeb886c1 100644 --- a/vlib/builtin/utf8.c.v +++ b/vlib/builtin/utf8.c.v @@ -7,6 +7,7 @@ const cp_utf8 = 65001 @[params] pub struct ToWideConfig { +pub: from_ansi bool } diff --git a/vlib/crypto/argon2/argon2.v b/vlib/crypto/argon2/argon2.v index 110ede8b6..2a44867e5 100644 --- a/vlib/crypto/argon2/argon2.v +++ b/vlib/crypto/argon2/argon2.v @@ -96,20 +96,17 @@ pub fn default_params() Params { // key derives a key from `password` and `salt` using Argon2i. pub fn key(password []u8, salt []u8, time u32, memory u32, threads u8, key_len u32) ![]u8 { - return derive_key(argon2_i, password, salt, []u8{}, []u8{}, time, memory, threads, - key_len) + return derive_key(argon2_i, password, salt, []u8{}, []u8{}, time, memory, threads, key_len) } // d_key derives a key from `password` and `salt` using Argon2d. pub fn d_key(password []u8, salt []u8, time u32, memory u32, threads u8, key_len u32) ![]u8 { - return derive_key(argon2_d, password, salt, []u8{}, []u8{}, time, memory, threads, - key_len) + return derive_key(argon2_d, password, salt, []u8{}, []u8{}, time, memory, threads, key_len) } // id_key derives a key from `password` and `salt` using Argon2id. pub fn id_key(password []u8, salt []u8, time u32, memory u32, threads u8, key_len u32) ![]u8 { - return derive_key(argon2_id, password, salt, []u8{}, []u8{}, time, memory, threads, - key_len) + return derive_key(argon2_id, password, salt, []u8{}, []u8{}, time, memory, threads, key_len) } // generate_from_password hashes `password` with default Argon2id parameters @@ -128,9 +125,10 @@ pub fn generate_from_password_with_params(password []u8, params Params) !string } } salt := rand.bytes(normalized.salt_len)! - hash := derive_key(argon2_id, password, salt, []u8{}, []u8{}, normalized.time, normalized.memory, - normalized.threads, normalized.key_len)! - return encode_hash(argon2_id, salt, hash, normalized.time, normalized.memory, normalized.threads) + hash := derive_key(argon2_id, password, salt, []u8{}, []u8{}, normalized.time, + normalized.memory, normalized.threads, normalized.key_len)! + return encode_hash(argon2_id, salt, hash, normalized.time, normalized.memory, + normalized.threads) } // compare_hash_and_password verifies a PHC-formatted Argon2 hash against `password`. @@ -170,8 +168,8 @@ fn derive_key(mode int, password []u8, salt []u8, secret []u8, data []u8, time u } threads_u32 := u32(threads) effective_memory := normalize_memory(memory, threads_u32) - h0 := init_hash(password, salt, secret, data, time, effective_memory, threads_u32, - key_len, mode)! + h0 := + init_hash(password, salt, secret, data, time, effective_memory, threads_u32, key_len, mode)! mut blocks := init_blocks(h0, effective_memory, threads_u32)! process_blocks(mut blocks, time, effective_memory, threads_u32, mode) return extract_key(mut blocks, effective_memory, threads_u32, key_len) @@ -295,8 +293,7 @@ fn process_segment(mut blocks []u64, pass u32, slice u32, lane u32, time u32, me } else { random = blocks[block_offset(prev)] } - new_offset := index_alpha(random, lanes, segments, threads, pass, slice, lane, - index) + new_offset := index_alpha(random, lanes, segments, threads, pass, slice, lane, index) process_block_xor_in_place(mut blocks, offset, prev, new_offset) index++ offset++ @@ -368,13 +365,14 @@ fn process_block_generic(mut out [block_length]u64, in1 [block_length]u64, in2 [ t[i] = in1[i] ^ in2[i] } for i := 0; i < block_length; i += 16 { - blamka_generic(mut t, i + 0, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, - i + 8, i + 9, i + 10, i + 11, i + 12, i + 13, i + 14, i + 15) + blamka_generic(mut t, i + 0, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9, + + i + 10, i + 11, i + 12, i + 13, i + 14, i + 15) } for i := 0; i < block_length / 8; i += 2 { - blamka_generic(mut t, i, i + 1, 16 + i, 16 + i + 1, 32 + i, 32 + i + 1, 48 + i, - 48 + i + 1, 64 + i, 64 + i + 1, 80 + i, 80 + i + 1, 96 + i, 96 + i + 1, 112 + i, - 112 + i + 1) + blamka_generic(mut t, i, i + 1, 16 + i, 16 + i + 1, 32 + i, 32 + i + 1, 48 + i, 48 + i + 1, + + 64 + i, 64 + i + 1, 80 + i, 80 + i + 1, 96 + i, 96 + i + 1, 112 + i, 112 + i + 1) } for i := 0; i < block_length; i++ { if xor { @@ -394,13 +392,14 @@ fn process_block_xor_in_place(mut blocks []u64, out_index u32, in1_index u32, in t[i] = blocks[in1_base + i] ^ blocks[in2_base + i] } for i := 0; i < block_length; i += 16 { - blamka_generic(mut t, i + 0, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, - i + 8, i + 9, i + 10, i + 11, i + 12, i + 13, i + 14, i + 15) + blamka_generic(mut t, i + 0, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9, + + i + 10, i + 11, i + 12, i + 13, i + 14, i + 15) } for i := 0; i < block_length / 8; i += 2 { - blamka_generic(mut t, i, i + 1, 16 + i, 16 + i + 1, 32 + i, 32 + i + 1, 48 + i, - 48 + i + 1, 64 + i, 64 + i + 1, 80 + i, 80 + i + 1, 96 + i, 96 + i + 1, 112 + i, - 112 + i + 1) + blamka_generic(mut t, i, i + 1, 16 + i, 16 + i + 1, 32 + i, 32 + i + 1, 48 + i, 48 + i + 1, + + 64 + i, 64 + i + 1, 80 + i, 80 + i + 1, 96 + i, 96 + i + 1, 112 + i, 112 + i + 1) } for i := 0; i < block_length; i++ { blocks[out_base + i] ^= blocks[in1_base + i] ^ blocks[in2_base + i] ^ t[i] diff --git a/vlib/flag/flag.v b/vlib/flag/flag.v index eeb24ac16..4f2889a5c 100644 --- a/vlib/flag/flag.v +++ b/vlib/flag/flag.v @@ -350,10 +350,16 @@ pub fn (mut fs FlagParser) bool_opt(name string, abbr u8, usage string, c FlagCo // bool defines and parses a bool flag/option named `name`. // If that flag is given by the user, then it returns its parsed bool value. // When it is not, it returns the default value in `bdefault`. -// Use a typed option default like `?bool(none)` to receive an optional result. // This version supports abbreviations. // This version supports a custom value description. -pub fn (mut fs FlagParser) bool[T](name string, abbr u8, bdefault T, usage string, c FlagConfig) T { +pub fn (mut fs FlagParser) bool(name string, abbr u8, bdefault bool, usage string, c FlagConfig) bool { + value := fs.bool_opt(name, abbr, usage, c) or { return bdefault } + return value +} + +// bool_val is a generic version of `bool` that supports optional defaults. +// Use `?bool(none)` as default to receive an optional result. +pub fn (mut fs FlagParser) bool_val[T](name string, abbr u8, bdefault T, usage string, c FlagConfig) T { value := fs.bool_opt(name, abbr, usage, c) or { return bdefault } return value } @@ -401,10 +407,16 @@ pub fn (mut fs FlagParser) int_opt(name string, abbr u8, usage string, c FlagCon // int defines and parses an integer flag, named `name`. // When the flag is given by the user, it returns its parsed integer value. // When it is not, it returns the integer value in `idefault`. -// Use a typed option default like `?int(none)` to receive an optional result. // This version supports abbreviations. // This version supports a custom value description. -pub fn (mut fs FlagParser) int[T](name string, abbr u8, idefault T, usage string, c FlagConfig) T { +pub fn (mut fs FlagParser) int(name string, abbr u8, idefault int, usage string, c FlagConfig) int { + value := fs.int_opt(name, abbr, usage, c) or { return idefault } + return value +} + +// int_val is a generic version of `int` that supports optional defaults. +// Use `?int(none)` as default to receive an optional result. +pub fn (mut fs FlagParser) int_val[T](name string, abbr u8, idefault T, usage string, c FlagConfig) T { value := fs.int_opt(name, abbr, usage, c) or { return idefault } return value } @@ -451,10 +463,16 @@ pub fn (mut fs FlagParser) float_opt(name string, abbr u8, usage string, c FlagC // float defines and parses a floating point flag, named `name`. // When the flag is given by the user, it returns its parsed floating point value. // When it is not, it returns the value in `fdefault`. -// Use a typed option default like `?f64(none)` to receive an optional result. // This version supports abbreviations. // This version supports a custom value description. -pub fn (mut fs FlagParser) float[T](name string, abbr u8, fdefault T, usage string, c FlagConfig) T { +pub fn (mut fs FlagParser) float(name string, abbr u8, fdefault f64, usage string, c FlagConfig) f64 { + value := fs.float_opt(name, abbr, usage, c) or { return fdefault } + return value +} + +// float_val is a generic version of `float` that supports optional defaults. +// Use `?f64(none)` as default to receive an optional result. +pub fn (mut fs FlagParser) float_val[T](name string, abbr u8, fdefault T, usage string, c FlagConfig) T { value := fs.float_opt(name, abbr, usage, c) or { return fdefault } return value } @@ -496,10 +514,16 @@ pub fn (mut fs FlagParser) string_opt(name string, abbr u8, usage string, c Flag // string defines and parses a string flag/option, named `name`. // If that flag is given as an option, then its parsed value is returned as a string. // When it is not, it returns the default string value in `sdefault`. -// Use a typed option default like `?string(none)` to receive an optional result. // This version supports abbreviations. // This version supports a custom value description. -pub fn (mut fs FlagParser) string[T](name string, abbr u8, sdefault T, usage string, c FlagConfig) T { +pub fn (mut fs FlagParser) string(name string, abbr u8, sdefault string, usage string, c FlagConfig) string { + value := fs.string_opt(name, abbr, usage, c) or { return sdefault } + return value +} + +// string_val is a generic version of `string` that supports optional defaults. +// Use `?string(none)` as default to receive an optional result. +pub fn (mut fs FlagParser) string_val[T](name string, abbr u8, sdefault T, usage string, c FlagConfig) T { value := fs.string_opt(name, abbr, usage, c) or { return sdefault } return value } diff --git a/vlib/net/ssl/ssl_notd_use_openssl.v b/vlib/net/ssl/ssl_notd_use_openssl.v index 28427db34..f0572d925 100644 --- a/vlib/net/ssl/ssl_notd_use_openssl.v +++ b/vlib/net/ssl/ssl_notd_use_openssl.v @@ -13,12 +13,12 @@ $if tinyc && (freebsd || openbsd) { openssl.SSLConn } + @[params] pub struct SSLConnectConfig { openssl.SSLConnectConfig } // new_ssl_conn returns a new SSLConn with the given config. - @[params] pub fn new_ssl_conn(config SSLConnectConfig) !&SSLConn { c := openssl.new_ssl_conn(config.SSLConnectConfig) or { return err } return &SSLConn{c} @@ -28,12 +28,12 @@ $if tinyc && (freebsd || openbsd) { mbedtls.SSLConn } + @[params] pub struct SSLConnectConfig { mbedtls.SSLConnectConfig } // new_ssl_conn returns a new SSLConn with the given config. - @[params] pub fn new_ssl_conn(config SSLConnectConfig) !&SSLConn { c := mbedtls.new_ssl_conn(config.SSLConnectConfig) or { return err } return &SSLConn{c} diff --git a/vlib/orm/orm_fn_test.v b/vlib/orm/orm_fn_test.v index 43fd35fbb..e2b577d8b 100644 --- a/vlib/orm/orm_fn_test.v +++ b/vlib/orm/orm_fn_test.v @@ -429,8 +429,7 @@ fn test_orm_table_gen() { }, ] } - table_unique_query := orm.orm_table_gen(.default, table_with_unique, "'", true, 0, - [ + table_unique_query := orm.orm_table_gen(.default, table_with_unique, "'", true, 0, [ orm.TableField{ name: 'id' typ: typeof[int]().idx diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index 6085363e9..6ace906d8 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -195,8 +195,8 @@ fn accept_callback(listen_fd int, _events int, cb_arg voidptr) { trace_fd('accept ${accepted_fd}') setup_sock(accepted_fd) or { elog('setup_sock failed, fd: ${accepted_fd}, listen_fd: ${listen_fd}, err: ${err.code()}') - pv.error_callback(pv.user_data, pico_http_parser.Request{}, mut &pico_http_parser.Response{}, - err) + pv.error_callback(pv.user_data, pico_http_parser.Request{}, mut + &pico_http_parser.Response{}, err) close_socket(accepted_fd) // Close fd on failure return } diff --git a/vlib/picoev/socket_util.c.v b/vlib/picoev/socket_util.c.v index 0815d5ae8..2e705a401 100644 --- a/vlib/picoev/socket_util.c.v +++ b/vlib/picoev/socket_util.c.v @@ -127,8 +127,8 @@ fn listen(config Config) !int { net.socket_error_message(C.listen(fd, C.SOMAXCONN), 'listening on ${saddr} with maximum backlog pending queue of ${C.SOMAXCONN}, failed')! setup_sock(fd) or { - config.err_cb(config.user_data, pico_http_parser.Request{}, mut &pico_http_parser.Response{}, - err) + config.err_cb(config.user_data, pico_http_parser.Request{}, mut + &pico_http_parser.Response{}, err) } return fd } diff --git a/vlib/toml/toml.v b/vlib/toml/toml.v index 81de37574..456884361 100644 --- a/vlib/toml/toml.v +++ b/vlib/toml/toml.v @@ -141,7 +141,7 @@ fn decode_struct[T](doc Any, mut typ T) { } } -fn decode_array[T](current []T, values []Any) []T { +fn decode_array[T](current []T, values []toml.Any) []T { $if T is string { return values.map(it.string()) } $else $if T is bool { diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index e5aabb135..94f7db8ed 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -714,7 +714,12 @@ pub fn (x Expr) str() string { return s + ' := ' + x.expr.str() } StructInit { - sname := global_table.sym(x.typ).name + idx := x.typ.idx() + sname := if idx > 0 && idx < global_table.type_symbols.len { + global_table.type_symbols[idx].name + } else { + 'unknown' + } return '${sname}{....}' } ArrayDecompose { diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index ee12739d9..bcabd5e9a 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -951,8 +951,8 @@ pub fn (t &Table) sym(typ Type) &TypeSymbol { if idx > 0 && idx < t.type_symbols.len { return t.type_symbols[idx] } - if idx == 65535 || typ == invalid_type { - // invalid_type is used as a sentinel during generic type resolution; + if idx == 0 || idx == 65535 || typ == invalid_type { + // invalid_type and idx=0 are used as sentinels during generic type resolution; // return a safe placeholder instead of panicking. return invalid_type_symbol } @@ -973,6 +973,9 @@ pub fn (t &Table) final_sym(typ Type) &TypeSymbol { } return t.type_symbols[idx] } + if idx == 0 { + return invalid_type_symbol + } // this should never happen t.panic('table.final_sym: invalid type (typ=${typ} idx=${idx}). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.') return invalid_type_symbol @@ -1036,8 +1039,7 @@ pub fn (t &Table) fully_unaliased_type(typ Type) Type { sym := t.sym(unaliased) if sym.info is Alias { parent_typ := sym.info.parent_type - unaliased = Type(u32(parent_typ.set_nr_muls(parent_typ.nr_muls() + - unaliased.nr_muls())) | extra_flags) + unaliased = Type(u32(parent_typ.set_nr_muls(parent_typ.nr_muls() + unaliased.nr_muls())) | extra_flags) extra_flags |= u32(unaliased) & 0xff00_0000 continue } @@ -3201,6 +3203,10 @@ fn (t &Table) find_fn_in_mod(name string, mod string) ?Fn { pub fn (mut t Table) generic_type_names(generic_type Type) []string { mut names := []string{} + idx := generic_type.idx() + if idx == 0 || idx >= t.type_symbols.len { + return names + } mut sym := t.sym(generic_type) if sym.name.len == 1 && sym.name[0].is_capital() { names << sym.name @@ -3358,10 +3364,10 @@ fn (mut t Table) unwrap_generic_type_ex_with_depth(typ Type, generic_names []str generic_names, concrete_types) } } - unwrapped_return_sym := t.sym(unwrapped_fn.return_type) if unwrapped_fn.return_type.has_flag(.generic) || t.generic_type_names(unwrapped_fn.return_type).len > 0 - || (unwrapped_return_sym.kind == .generic_inst&& (unwrapped_return_sym.info as GenericInst).concrete_types.any(it.has_flag(.generic))) { + || (unwrapped_fn.return_type.idx() > 0 && unwrapped_fn.return_type.idx() < t.type_symbols.len + && t.sym(unwrapped_fn.return_type).kind == .generic_inst&& (t.sym(unwrapped_fn.return_type).info as GenericInst).concrete_types.any(it.has_flag(.generic))) { unwrapped_fn.return_type = t.unwrap_generic_type_ex_with_depth(unwrapped_fn.return_type, generic_names, concrete_types, recheck_concrete_types, depth_guard) has_generic = true diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index e122d4548..ef2c2b9d7 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -584,6 +584,10 @@ pub fn (t Type) str() string { } pub fn (t &Table) type_str(typ Type) string { + idx := typ.idx() + if idx == 0 || idx >= t.type_symbols.len { + return 'unknown' + } return t.sym(typ).name } @@ -1609,6 +1613,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] return cached_res } } + idx := typ.idx() + if idx == 0 || idx >= t.type_symbols.len { + return 'unknown' + } sym := t.sym(typ) mut res := sym.name defer { diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index afea6c0c1..363661784 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -17,7 +17,7 @@ pub fn compile(command string, pref_ &pref.Preferences, backend_cb FnBackend) { if pref_.backend == .c { // Resolve the effective Windows C compiler before builder initialization. mut probe := Builder{ - pref: pref_ + pref: unsafe { pref_ } } probe.find_win_cc() or {} } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4dd76b8f6..10b8772b4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -191,8 +191,7 @@ pub fn new_checker(table &ast.Table, pref_ &pref.Preferences) &Checker { ) match_exhaustive_cutoff_limit: pref_.checker_match_exhaustive_cutoff_limit v_current_commit_hash: v_current_commit_hash - checker_transformer: transformer.new_transformer_with_table(table, - pref_) + checker_transformer: transformer.new_transformer_with_table(table, pref_) visible_param_mutation_cache: map[string]bool{} visible_param_mutation_in_progress: map[string]bool{} } @@ -1445,8 +1444,7 @@ fn (mut c Checker) return_expr_immutable_alias_source(expr ast.Expr, func ast.Fn } } if expr.obj is ast.Var && (allow_non_ptr || expr.obj.typ.is_ptr()) { - return c.return_expr_immutable_alias_source(expr.obj.expr, func, call, - false) + return c.return_expr_immutable_alias_source(expr.obj.expr, func, call, false) } return ast.empty_expr } @@ -1544,8 +1542,7 @@ fn (mut c Checker) fail_if_immutable_to_mutable(left_type ast.Type, right_type a c.note('`${source.name}` is immutable, cannot have a mutable reference to an immutable object', source.pos) } else { - c.note('call result aliases mutable data from an immutable value', - right.pos) + c.note('call result aliases mutable data from an immutable value', right.pos) } return false } diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index a5a7eed7a..a39b64bb9 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -326,7 +326,8 @@ fn (mut c Checker) comptime_selector_method_value(mut node ast.ComptimeSelector) node.is_method = true fn_type := c.type_resolver.get_comptime_selector_type(node, ast.void_type) node.typ = c.unwrap_generic(fn_type) - c.markused_comptime_call(node.left_type.has_flag(.generic), '${int(method.params[0].typ)}.${method.name}') + c.markused_comptime_call(node.left_type.has_flag(.generic), + '${int(method.params[0].typ)}.${method.name}') receiver := c.unwrap_generic(method.params[0].typ) if receiver.nr_muls() > 0 && !c.inside_unsafe { rec_sym := c.table.sym(receiver.set_nr_muls(0)) diff --git a/vlib/v/checker/visible_mutation.v b/vlib/v/checker/visible_mutation.v index 394db8b8d..9208b1b91 100644 --- a/vlib/v/checker/visible_mutation.v +++ b/vlib/v/checker/visible_mutation.v @@ -101,9 +101,7 @@ fn (mut c Checker) expr_has_visible_mutation(expr ast.Expr, root_name string, ro } } ast.PostfixExpr { - if is_visible_root_mutation(c.expr_mutation_visibility(expr.expr, root_name, - root_type)) - { + if is_visible_root_mutation(c.expr_mutation_visibility(expr.expr, root_name, root_type)) { return true } } diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 21da5e6ae..d2beabaab 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -181,8 +181,8 @@ fn test_all() { tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false) tasks.add('', module_dir, '-prod run', '.out', module_tests, true) tasks.add('', run_dir, 'run', '.run.out', run_tests, false) - tasks.add('', checker_dir, '-disable-explicit-mutability run', '.disable_explicit_mutability.run.out', - disable_explicit_mutability_tests, false) + tasks.add('', checker_dir, '-disable-explicit-mutability run', + '.disable_explicit_mutability.run.out', disable_explicit_mutability_tests, false) tasks.add('', checker_with_check_option_dir, '-check', '.out', checker_with_check_option_tests, false) tasks.add('', no_closures_dir, '-no-closures run', '.out', no_closures_tests, false) diff --git a/vlib/v/gen/c/assert.v b/vlib/v/gen/c/assert.v index f5335fbfb..4737b5580 100644 --- a/vlib/v/gen/c/assert.v +++ b/vlib/v/gen/c/assert.v @@ -167,9 +167,9 @@ fn (mut g Gen) gen_assert_postfailure_mode(node ast.AssertStmt) { || g.fn_decl.attrs.any(it.name == 'assert_continues') { return } - if g.pref.is_test && g.cur_fn != unsafe { nil } && g.cur_fn.scope != unsafe { nil } { - g.write_defer_stmts_when_needed(g.innermost_active_defer_scope(node.pos), true, - node.pos) + if g.pref.is_test && !g.inside_defer_generation && g.cur_fn != unsafe { nil } + && g.cur_fn.scope != unsafe { nil } { + g.write_defer_stmts_when_needed(g.innermost_active_defer_scope(node.pos), true, node.pos) } if g.pref.assert_failure_mode == .aborts || g.fn_decl.attrs.any(it.name == 'assert_aborts') { g.writeln('\tabort();') diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 7957e08ff..2b0c955b4 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -138,6 +138,9 @@ fn (mut g Gen) decl_assign_struct_init_needs_tmp(expr ast.Expr) bool { if sym.info !is ast.Struct { return false } + if g.styp(node.typ) in skip_struct_init { + return false + } info := sym.info as ast.Struct if node.no_keys { return node.init_fields.len < info.fields.len diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 727d6c308..8bdace3a1 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -192,6 +192,7 @@ mut: defer_stmts []ast.DeferStmt defer_ifdef string defer_profile_code string + inside_defer_generation bool defer_vars []string closure_structs []string str_types []StrType // types that need automatic str() generation diff --git a/vlib/v/gen/c/defer.v b/vlib/v/gen/c/defer.v index ec0d2e14e..96527cb57 100644 --- a/vlib/v/gen/c/defer.v +++ b/vlib/v/gen/c/defer.v @@ -34,6 +34,11 @@ fn (mut g Gen) write_defer_stmts(scope &ast.Scope, lookup bool, pos token.Pos) { g.error('Gen.write_defer_stmts() has received a scope that is nil', pos) } + prev_inside_defer_generation := g.inside_defer_generation + g.inside_defer_generation = true + defer { + g.inside_defer_generation = prev_inside_defer_generation + } g.indent++ for i := g.defer_stmts.len - 1; i >= 0; i-- { defer_stmt := g.defer_stmts[i] diff --git a/vlib/v/gen/c/for.v b/vlib/v/gen/c/for.v index 858c848fd..51a3af85e 100644 --- a/vlib/v/gen/c/for.v +++ b/vlib/v/gen/c/for.v @@ -70,8 +70,12 @@ fn (mut g Gen) for_c_stmt(node ast.ForCStmt) { g.is_vlines_enabled = true g.inside_for_c_stmt = false g.write_labeled_continue_gate(node.label, '') + if node.label.len > 0 { + g.writeln('{') + } g.stmts(node.stmts) if node.label.len > 0 { + g.writeln('}') g.writeln('${node.label}__continue: {}') } g.writeln('}') @@ -127,8 +131,12 @@ fn (mut g Gen) for_c_stmt(node ast.ForCStmt) { g.is_vlines_enabled = true g.inside_for_c_stmt = false g.write_labeled_continue_gate(node.label, '') + if node.label.len > 0 { + g.writeln('{') + } g.stmts(node.stmts) if node.label.len > 0 { + g.writeln('}') g.writeln('${node.label}__continue: {}') } g.write_defer_stmts(node.scope, false, node.pos) @@ -157,8 +165,12 @@ fn (mut g Gen) for_stmt(node ast.ForStmt) { } g.is_vlines_enabled = true g.write_labeled_continue_gate(node.label, '\t') + if node.label.len > 0 { + g.writeln('\t{') + } g.stmts(node.stmts) if node.label.len > 0 { + g.writeln('\t}') g.writeln('\t${node.label}__continue: {}') } g.write_defer_stmts(node.scope, false, node.pos) @@ -806,8 +818,12 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) { g.error('for in: unhandled symbol `${node.cond}` of type `${typ_str}`', node.pos) } g.write_labeled_continue_gate(node.label, '\t') + if node.label.len > 0 { + g.writeln('\t{') + } g.stmts(node.stmts) if node.label.len > 0 { + g.writeln('\t}') g.writeln('\t${node.label}__continue: {}') } diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index 262380e8e..600455fb3 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -1733,7 +1733,8 @@ struct VSafeArithmeticOp { } fn (mut g Gen) normalized_power_result_type(result_type ast.Type, left_type ast.Type, right_type ast.Type) ast.Type { - mut typ := g.unwrap_generic(g.recheck_concrete_type(result_type)).clear_flag(.shared_f).clear_flag(.atomic_f) + mut typ := + g.unwrap_generic(g.recheck_concrete_type(result_type)).clear_flag(.shared_f).clear_flag(.atomic_f) if typ == 0 || typ == ast.void_type { typ = g.unwrap_generic(g.type_resolver.promote_type(g.unwrap_generic(left_type), g.unwrap_generic(right_type))).clear_flag(.shared_f).clear_flag(.atomic_f) diff --git a/vlib/v/gen/c/labelled_continue_scope_test.v b/vlib/v/gen/c/labelled_continue_scope_test.v index 34fa13d97..9651f1fb1 100644 --- a/vlib/v/gen/c/labelled_continue_scope_test.v +++ b/vlib/v/gen/c/labelled_continue_scope_test.v @@ -4,7 +4,8 @@ const vexe = @VEXE const vroot = os.real_path(@VMODROOT) -const labelled_continue_scope_testdata = os.join_path(vroot, 'vlib/v/gen/c/testdata/labelled_continue_scope.vv') +const labelled_continue_scope_testdata = os.join_path(vroot, + 'vlib/v/gen/c/testdata/labelled_continue_scope.vv') struct LabelledContinueCase { label string diff --git a/vlib/v/gen/c/sql_assert_temp_var_test.v b/vlib/v/gen/c/sql_assert_temp_var_test.v index dffe3e521..ec8f1ab3e 100644 --- a/vlib/v/gen/c/sql_assert_temp_var_test.v +++ b/vlib/v/gen/c/sql_assert_temp_var_test.v @@ -4,7 +4,8 @@ const sql_assert_temp_var_vexe = @VEXE const sql_assert_temp_var_vroot = os.real_path(@VMODROOT) -const sql_assert_temp_var_testdata = os.join_path(sql_assert_temp_var_vroot, 'vlib/v/gen/c/testdata/assert_sql_select_sub_array_field.vv') +const sql_assert_temp_var_testdata = os.join_path(sql_assert_temp_var_vroot, + 'vlib/v/gen/c/testdata/assert_sql_select_sub_array_field.vv') fn test_assert_with_inline_sql_select_compiles() { os.chdir(sql_assert_temp_var_vroot) or {} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 0ed7d35cc..3c4937008 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -12,6 +12,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl { p.top_level_statement_start() // save attributes, they will be changed later in fields attrs := p.attrs + p.attrs = [] start_pos := p.tok.pos() mut is_pub := p.tok.kind == .key_pub mut is_shared := p.tok.kind == .key_shared diff --git a/vlib/v/pref/pref_test.v b/vlib/v/pref/pref_test.v index c4a525d1a..6ca8e745b 100644 --- a/vlib/v/pref/pref_test.v +++ b/vlib/v/pref/pref_test.v @@ -54,8 +54,7 @@ fn test_cross_compile_keeps_explicit_cc() { fn test_disable_explicit_mutability_flag() { target := os.join_path(vroot, 'examples', 'hello_world.v') - prefs, _ := pref.parse_args_and_show_errors([], ['-disable-explicit-mutability', target], - false) + prefs, _ := pref.parse_args_and_show_errors([], ['-disable-explicit-mutability', target], false) assert prefs.disable_explicit_mutability assert prefs.build_options.contains('-disable-explicit-mutability') @@ -224,8 +223,8 @@ fn test_missing_explicit_ccompiler_reports_error() { os.execute('${os.quoted_path(@VEXE)} -cc ${missing_cc} -o ${os.quoted_path(output)} ${os.quoted_path(target)}') assert res.exit_code != 0 assert res.output.contains(missing_cc), res.output - assert res.output.to_lower().contains('not found') || res.output.to_lower().contains('missing'), - res.output + assert res.output.to_lower().contains('not found') || res.output.to_lower().contains('missing'), res.output + assert !os.exists(expected_output) } diff --git a/vlib/v/tests/failing_tests_test.v b/vlib/v/tests/failing_tests_test.v index 6fa071b09..d744577bc 100644 --- a/vlib/v/tests/failing_tests_test.v +++ b/vlib/v/tests/failing_tests_test.v @@ -1,6 +1,7 @@ import os -const assert_failed_defer_cleanup_path = os.join_path(os.vtmp_dir(), 'v_assert_failed_defer_cleanup_test.txt') +const assert_failed_defer_cleanup_path = os.join_path(os.vtmp_dir(), + 'v_assert_failed_defer_cleanup_test.txt') fn vroot_path(relpath string) string { return os.real_path(os.join_path(@VMODROOT, relpath)) diff --git a/vlib/v/tests/fns/multiline_fn_signature_omitted_comma_test.v b/vlib/v/tests/fns/multiline_fn_signature_omitted_comma_test.v index e3115313a..478d199a5 100644 --- a/vlib/v/tests/fns/multiline_fn_signature_omitted_comma_test.v +++ b/vlib/v/tests/fns/multiline_fn_signature_omitted_comma_test.v @@ -1,7 +1,8 @@ import os fn test_multiline_fn_signature_can_omit_commas() { - source_path := os.join_path(os.vtmp_dir(), 'issue_22021_multiline_fn_signature_${os.getpid()}.v') + source_path := os.join_path(os.vtmp_dir(), + 'issue_22021_multiline_fn_signature_${os.getpid()}.v') source := "fn multiline_greet(\n\tsalutation string\n\tname string\n) string {\n\treturn 'Hey, ' + salutation + ' ' + name + '!'\n}\n\nfn main() {\n\tassert multiline_greet(\n\t\t'Mr.'\n\t\t'Joe'\n\t) == 'Hey, Mr. Joe!'\n\tgreeter := fn (salutation string\n\t\tname string) string {\n\t\treturn 'Hello, ' + salutation + ' ' + name + '!'\n\t}\n\tassert greeter('Ms.', 'Jane') == 'Hello, Ms. Jane!'\n}\n" os.write_file(source_path, source)! defer { diff --git a/vlib/v/tests/local_module_submodules_test.v b/vlib/v/tests/local_module_submodules_test.v index 92238537e..f410d60d8 100644 --- a/vlib/v/tests/local_module_submodules_test.v +++ b/vlib/v/tests/local_module_submodules_test.v @@ -44,10 +44,12 @@ fn write_issue_24649_project() { '\n') or { panic(err) } os.write_file(os.join_path(basepath, 'my_math', 'floating.v'), ['module my_math', '', 'pub fn addition(x f64, y f64) f64 {', '\treturn x + - y', '}'].join('\n') + '\n') or { panic(err) } + y', '}'].join('\n') + + '\n') or { panic(err) } os.write_file(os.join_path(basepath, 'my_math', 'my_integer', 'integer.v'), ['module my_integer', '', 'pub fn addition(x f64, y f64) int {', '\treturn int(x + - y)', '}'].join('\n') + '\n') or { panic(err) } + y)', '}'].join('\n') + + '\n') or { panic(err) } } fn compile_local_module_submodules(target string, out_name string) os.Result { diff --git a/vlib/v/util/util_test.v b/vlib/v/util/util_test.v index 6626ea891..91e0c67d2 100644 --- a/vlib/v/util/util_test.v +++ b/vlib/v/util/util_test.v @@ -21,8 +21,7 @@ fn test_fallback_tool_executable_path_uses_vtmp_for_missing_single_file_tool() { os.write_file(tool_source, 'fn main() {}') or { panic(err) } tool_exe := os.join_path(tmp_dir, 'vdoctor') - fallback := fallback_tool_executable_path('/opt/vlang', 'vdoctor', tool_source, tool_exe, - true) + fallback := fallback_tool_executable_path('/opt/vlang', 'vdoctor', tool_source, tool_exe, true) assert fallback != tool_exe assert fallback.starts_with(os.join_path(os.vtmp_dir(), 'tools')) @@ -39,8 +38,7 @@ fn test_fallback_tool_executable_path_keeps_directory_tools_in_place() { os.mkdir_all(tool_source) or { panic(err) } tool_exe := os.join_path(tool_source, 'vdoc') - fallback := fallback_tool_executable_path('/opt/vlang', 'vdoc', tool_source, tool_exe, - true) + fallback := fallback_tool_executable_path('/opt/vlang', 'vdoc', tool_source, tool_exe, true) assert fallback == tool_exe } -- 2.39.5