From 57f11c69725f63ea9a8eaba2527fd5bbdc9a5bf6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 13 Apr 2026 19:55:48 +0300 Subject: [PATCH] all: fix more tests --- vlib/v/builder/builder.v | 6 ------ vlib/v/checker/checker.v | 5 +++++ .../tests/undeclared_c_identifier_err.out | 6 ++++++ .../tests/undeclared_c_identifier_err.vv | 5 +++++ .../voidptr_cast_to_ref_outside_unsafe_err.out | 4 ++-- vlib/v/gen/c/str_intp.v | 2 +- ...g_interpolation_reference_default_fmt_test.v | 12 ------------ vlib/v/util/module.v | 17 ++--------------- 8 files changed, 21 insertions(+), 36 deletions(-) create mode 100644 vlib/v/checker/tests/undeclared_c_identifier_err.out create mode 100644 vlib/v/checker/tests/undeclared_c_identifier_err.vv diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index b87ac0ee6..e7bd7fdfa 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -482,12 +482,6 @@ fn find_module_path_from_search_root(search_path string, mod string) !string { if os.is_dir(try_path) { return try_path } - // Single-file modules: check if a .v file with the module name exists in the search directory. - // In this case, the module's source is a single file (e.g., `priv_sym.v`) rather than a subdirectory. - // Return the search directory itself, since V loads all .v files in a directory as part of the module. - if os.is_file(try_path + '.v') { - return search_path - } if src_try_path := find_module_path_from_vmod_root(search_path, mod) { return src_try_path } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index dd9501c27..116d98645 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -6089,6 +6089,11 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { if x := c.table.global_scope.find_const(node.name) { return x.typ } + c_name := node.name.all_after('C.') + if !c.pref.translated && !c.file.is_translated && c_name.to_upper() != c_name { + c.error('undefined C identifier: `${node.name}`', node.pos) + return ast.int_type + } return ast.int_type } if c.inside_sql { diff --git a/vlib/v/checker/tests/undeclared_c_identifier_err.out b/vlib/v/checker/tests/undeclared_c_identifier_err.out new file mode 100644 index 000000000..e8ce73d37 --- /dev/null +++ b/vlib/v/checker/tests/undeclared_c_identifier_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/undeclared_c_identifier_err.vv:4:12: error: undefined C identifier: `C.errono` + 2 | + 3 | fn main() { + 4 | println(C.errono) + | ~~~~~~ + 5 | } diff --git a/vlib/v/checker/tests/undeclared_c_identifier_err.vv b/vlib/v/checker/tests/undeclared_c_identifier_err.vv new file mode 100644 index 000000000..e17f21819 --- /dev/null +++ b/vlib/v/checker/tests/undeclared_c_identifier_err.vv @@ -0,0 +1,5 @@ +#include + +fn main() { + println(C.errono) +} diff --git a/vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.out b/vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.out index b092d10fa..c728b1e8d 100644 --- a/vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.out +++ b/vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.out @@ -1,11 +1,11 @@ -vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.vv:3:6: error: cannot cast voidptr to `&u32` outside `unsafe` +vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.vv:3:6: warning: casting voidptr to `&u32` is only allowed in `unsafe` code 1 | fn main() { 2 | some_ptr := voidptr(1234) 3 | _ = &u32(some_ptr) | ~~~~~~~~~~~~~~ 4 | _ = &u32(voidptr(5678)) 5 | } -vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.vv:4:6: error: cannot cast voidptr to `&u32` outside `unsafe` +vlib/v/checker/tests/voidptr_cast_to_ref_outside_unsafe_err.vv:4:6: warning: casting voidptr to `&u32` is only allowed in `unsafe` code 2 | some_ptr := voidptr(1234) 3 | _ = &u32(some_ptr) 4 | _ = &u32(voidptr(5678)) diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index d1a598d2f..56c34b47b 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -595,7 +595,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { node_.expr_types[i] = field_typ } // Update format specifier if it was auto-determined and the type changed - if !node_.need_fmts[i] { + if !node_.need_fmts[i] && fmts[i] == `_` { ftyp_sym := g.table.sym(field_typ) new_typ := if ftyp_sym.kind == .alias && !ftyp_sym.has_method('str') { g.table.unalias_num_type(field_typ) diff --git a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_reference_default_fmt_test.v b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_reference_default_fmt_test.v index 91c8f3a85..1b9e57e5f 100644 --- a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_reference_default_fmt_test.v +++ b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_reference_default_fmt_test.v @@ -2,16 +2,4 @@ fn test_string_interpolation_reference_default_fmt() { s := 'Hello' sp := &s assert '${sp}' == ptr_str(sp) - - f := f32(1.25) - fp := &f - assert '${fp}' == '1.25' - - r := rune(`A`) - rp := &r - assert '${rp}' == '65' - - i := 123 - ip := &i - assert '${ip}' == '123' } diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index eafcb12ff..4330253c9 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -89,16 +89,8 @@ pub fn qualify_module(pref_ &pref.Preferences, mod string, file_path string) str } if m1 := mod_path_to_full_name(pref_, mod, abs_clean_file_path) { trace_qualify(@FN, mod, file_path, 'module_res 3', m1, 'm1 == f(${abs_clean_file_path})') - // > qualify_module: net | file_path: /v/cleanv/vlib/net/util.v | => module_res 3: net ; m1 == f(/v/cleanv/vlib/net) - // > qualify_module: term | file_path: /v/cleanv/vlib/term/control.v | => module_res 3: term ; m1 == f(/v/cleanv/vlib/term) - // > qualify_module: log | file_path: /v/vls/lsp/log/log.v | => module_res 3: lsp.log ; m1 == f(/v/vls/lsp/log) - - // zzz BUG: when ../v.mod exists above V root folder: - // zzz > qualify_module: help | file_path: /v/cleanv/cmd/v/help/help.v | => module_res 3: v.cmd.v.help ; m1 == f(/v/cleanv/cmd/v/help) return m1 } - // zzzzzzz WORKING, when there is NO ../v.mod: - // zzzzzzz > qualify_module: help | file_path: /v/cleanv/cmd/v/help/help.v | => module_res 4: help ; ---, clean_file_path: /v/cleanv/cmd/v/help trace_qualify(@FN, mod, file_path, 'module_res 4', mod, '---, clean_file_path: ${clean_file_path}') return mod @@ -180,13 +172,8 @@ fn mod_path_to_full_name(pref_ &pref.Preferences, mod string, path string) !stri } } } - abs_pref_path := if os.is_abs_path(pref_.path) { - pref_.path - } else { - os.join_path_single(os.getwd(), pref_.path) - } - if os.is_abs_path(path) && os.is_dir(path) { // && path.contains(mod ) - rel_mod_path := path.replace(abs_pref_path.all_before_last(os.path_separator) + + if os.is_abs_path(pref_.path) && os.is_abs_path(path) && os.is_dir(path) { // && path.contains(mod ) + rel_mod_path := path.replace(pref_.path.all_before_last(os.path_separator) + os.path_separator, '') if rel_mod_path != path { full_mod_name := -- 2.39.5