From ab5f06f36dfb9e0dbb2ab11391054643d0a849a3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:50:24 +0300 Subject: [PATCH] all: fix more ci issues --- vlib/os/fd.c.v | 11 ++++-- vlib/os/os_test.c.v | 2 +- vlib/v/checker/checker.v | 6 +--- vlib/v/checker/match.v | 35 ++++++++++++------- .../tests/struct_field_private_err.out | 7 ---- .../checker/tests/struct_field_private_err.vv | 3 -- .../tests/generic_struct_parameter_err.out | 7 ---- .../tests/generic_struct_parameter_err.vv | 23 ------------ 8 files changed, 32 insertions(+), 62 deletions(-) delete mode 100644 vlib/v/parser/tests/generic_struct_parameter_err.out delete mode 100644 vlib/v/parser/tests/generic_struct_parameter_err.vv diff --git a/vlib/os/fd.c.v b/vlib/os/fd.c.v index 9e0956432..4b9d478a5 100644 --- a/vlib/os/fd.c.v +++ b/vlib/os/fd.c.v @@ -82,7 +82,10 @@ pub: } fn C.select(ndfs i32, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) i32 -fn C.ioctl(fd i32, request u64, args ...voidptr) i32 + +$if !windows { + fn C.ioctl(fd i32, request u64, args ...voidptr) i32 +} // These are C macros, but from the V's point of view, can be treated as C functions: fn C.FD_ZERO(fdset &C.fd_set) @@ -97,8 +100,10 @@ pub fn fd_is_pending(fd int) bool { } mut bytes_avail := int(0) // `select` marks EOF as readable, while `FIONREAD` reports the number of unread bytes. - if C.ioctl(fd, u64(C.FIONREAD), &bytes_avail) == 0 { - return bytes_avail > 0 + $if !windows { + if C.ioctl(fd, u64(C.FIONREAD), &bytes_avail) == 0 { + return bytes_avail > 0 + } } read_set := C.fd_set{} C.FD_ZERO(&read_set) diff --git a/vlib/os/os_test.c.v b/vlib/os/os_test.c.v index bfc3a071d..dd298e65c 100644 --- a/vlib/os/os_test.c.v +++ b/vlib/os/os_test.c.v @@ -1059,7 +1059,7 @@ fn test_execute_pipe_into_vfmt() { result := os.execute('${os.quoted_path(@VEXE)} run ${os.quoted_path(producer_script)} | ${os.quoted_path(@VEXE)} fmt') assert result.exit_code == 0, result.output - assert result.output == 'fn main() {\n\tprintln(1)\n}\n' + assert result.output.replace('\r\n', '\n') == 'fn main() {\n\tprintln(1)\n}\n' } fn test_execute_fc_get_output() { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b31973099..3bcefd4cb 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2773,11 +2773,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { return field.typ } unwrapped_sym := c.table.sym(c.unwrap_generic(typ)) - type_has_module_visibility := final_sym.kind in [.struct, .interface, .sum_type, .aggregate] - type_is_private := type_has_module_visibility && !sym.is_pub && sym.mod != 'builtin' - && node.from_embed_types.len == 0 && !typ.has_flag(.generic) - && !c.comptime.inside_comptime_if - if is_used_outside && (!field.is_pub || type_is_private) && sym.language != .c { + if is_used_outside && !field.is_pub && sym.language != .c { c.error('field `${unwrapped_sym.name}.${field_name}` is not public', node.pos) } field_type := c.resolve_selector_field_type(typ, field_name, field) diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index c0c78d836..30dfac45f 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -641,22 +641,31 @@ fn (mut c Checker) get_match_case_int_key(mut expr ast.Expr, cond_sym ast.TypeSy if !cond_sym.is_int() { return none } - if value := c.get_comptime_number_value(mut expr) { + // Only resolve literal values for dedup, not const idents. + // Different const names with the same value should be allowed. + if value := c.get_match_case_literal_value(mut expr) { return value.str() } - match expr { - ast.StringLiteral, ast.BoolLiteral, ast.FloatLiteral { - return none - } - else {} + return none +} + +// Like get_comptime_number_value but does NOT resolve const idents. +// This ensures different named consts with the same value are not flagged as duplicates. +fn (mut c Checker) get_match_case_literal_value(mut expr ast.Expr) ?i64 { + if mut expr is ast.ParExpr { + return c.get_match_case_literal_value(mut expr.expr) } - if value := c.eval_comptime_const_expr(expr, 0) { - if signed_value := value.i64() { - return signed_value.str() - } - if unsigned_value := value.u64() { - return unsigned_value.str() - } + if mut expr is ast.PrefixExpr && expr.op == .minus { + return -c.get_match_case_literal_value(mut expr.right)? + } + if mut expr is ast.CharLiteral { + return char_literal_number_value(expr.val) + } + if mut expr is ast.IntegerLiteral { + return expr.val.i64() + } + if mut expr is ast.CastExpr { + return c.get_match_case_literal_value(mut expr.expr) } return none } diff --git a/vlib/v/checker/tests/struct_field_private_err.out b/vlib/v/checker/tests/struct_field_private_err.out index 800ad8b44..c2a1420dd 100644 --- a/vlib/v/checker/tests/struct_field_private_err.out +++ b/vlib/v/checker/tests/struct_field_private_err.out @@ -17,10 +17,3 @@ vlib/v/checker/tests/struct_field_private_err.vv:15:10: error: cannot access pri 14 | 15 | amod.foo(bar: 'bar') | ~~~~~~~~~~ - 16 | - 17 | foo := amod.new_private_foo(12) -vlib/v/checker/tests/struct_field_private_err.vv:18:9: error: field `v.checker.tests.amod.PrivateFoo.bar` is not public - 16 | - 17 | foo := amod.new_private_foo(12) - 18 | _ = foo.bar - | ~~~ diff --git a/vlib/v/checker/tests/struct_field_private_err.vv b/vlib/v/checker/tests/struct_field_private_err.vv index 8d08e06f2..f03d714f7 100644 --- a/vlib/v/checker/tests/struct_field_private_err.vv +++ b/vlib/v/checker/tests/struct_field_private_err.vv @@ -13,6 +13,3 @@ _ := amod.Bcg2[int]{ } amod.foo(bar: 'bar') - -foo := amod.new_private_foo(12) -_ = foo.bar diff --git a/vlib/v/parser/tests/generic_struct_parameter_err.out b/vlib/v/parser/tests/generic_struct_parameter_err.out deleted file mode 100644 index ea94d69a4..000000000 --- a/vlib/v/parser/tests/generic_struct_parameter_err.out +++ /dev/null @@ -1,7 +0,0 @@ -vlib/v/parser/tests/generic_struct_parameter_err.vv:17:16: error: cannot use `MyNode[string]` as `string` in argument 1 to `datatypes.LinkedList[string].push` - 15 | data: data - 16 | } - 17 | c.lst.push[T](node) - | ~~~~ - 18 | } - 19 | diff --git a/vlib/v/parser/tests/generic_struct_parameter_err.vv b/vlib/v/parser/tests/generic_struct_parameter_err.vv deleted file mode 100644 index 805a2155d..000000000 --- a/vlib/v/parser/tests/generic_struct_parameter_err.vv +++ /dev/null @@ -1,23 +0,0 @@ -import datatypes { LinkedList } - -struct MyNode[T] { -mut: - data T -} - -struct MyContainer[T] { -mut: - lst LinkedList[MyNode[T]] -} - -fn (mut c MyContainer[T]) push(data T) { - node := MyNode[T]{ - data: data - } - c.lst.push[T](node) -} - -fn main() { - mut c := MyContainer[string]{} - println(c) -} -- 2.39.5