From f375d18f4ba41abcf55d2cb534c29c9670a6dee8 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:26 +0300 Subject: [PATCH] parser: module function name conflict to keyword/type (fixes #23173) --- vlib/v/parser/parser.v | 6 ++++-- .../same_module_type_name_fn.v | 15 +++++++++++++++ .../tests/modules/same_module_type_name_fn_test.v | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/modules/same_module_type_name_fn/same_module_type_name_fn.v create mode 100644 vlib/v/tests/modules/same_module_type_name_fn_test.v diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 72eddc3b9..46f5f09f6 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1716,9 +1716,11 @@ fn (mut p Parser) name_expr() ast.Expr { p.add_defer_var(ident) return node } + // prepend the full import + mod = p.imports[p.tok.lit] + } else if p.mod.all_after_last('.') == p.tok.lit { + mod = p.mod } - // prepend the full import - mod = p.imports[p.tok.lit] } line_nr := p.tok.line_nr p.next() diff --git a/vlib/v/tests/modules/same_module_type_name_fn/same_module_type_name_fn.v b/vlib/v/tests/modules/same_module_type_name_fn/same_module_type_name_fn.v new file mode 100644 index 000000000..c0ef489c3 --- /dev/null +++ b/vlib/v/tests/modules/same_module_type_name_fn/same_module_type_name_fn.v @@ -0,0 +1,15 @@ +module same_module_type_name_fn + +// i64 returns a value from a same-module function whose name matches a builtin type. +pub fn i64() i64 { + return 1 +} + +// vfmt off +const module_value = same_module_type_name_fn.i64() +// vfmt on + +// get_value returns the const initialized through the same-module selector call. +pub fn get_value() i64 { + return module_value +} diff --git a/vlib/v/tests/modules/same_module_type_name_fn_test.v b/vlib/v/tests/modules/same_module_type_name_fn_test.v new file mode 100644 index 000000000..3967ec36f --- /dev/null +++ b/vlib/v/tests/modules/same_module_type_name_fn_test.v @@ -0,0 +1,8 @@ +module main + +import same_module_type_name_fn + +fn test_same_module_function_name_can_match_builtin_type() { + assert same_module_type_name_fn.i64() == i64(1) + assert same_module_type_name_fn.get_value() == i64(1) +} -- 2.39.5