From 2697f9788fd55133a3e9dfc44b27125bf06dd47c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:23 +0300 Subject: [PATCH] cgen: Assigning C.var to var triggers a compiler bug. (fixes #15971) --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/tests/c_errno_name_clash_test.c.v | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/c_errno_name_clash_test.c.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 90e7d2d62..f65d25051 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -24,7 +24,7 @@ const c_reserved = ['asm', 'array', 'auto', 'bool', 'break', 'calloc', 'case', ' 'long', 'malloc', 'namespace', 'new', 'nil', 'panic', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename', 'typeof', 'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'stdout', 'stdin', - 'stderr', 'requires'] + 'stderr', 'errno', 'environ', 'requires'] const c_reserved_chk = token.new_keywords_matcher_from_array_trie(c_reserved) // same order as in token.Kind const cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] diff --git a/vlib/v/tests/c_errno_name_clash_test.c.v b/vlib/v/tests/c_errno_name_clash_test.c.v new file mode 100644 index 000000000..ea82a01e3 --- /dev/null +++ b/vlib/v/tests/c_errno_name_clash_test.c.v @@ -0,0 +1,11 @@ +#include + +fn test_assigning_c_errno_to_same_named_local_var() { + old_errno := C.errno + defer { + C.errno = old_errno + } + C.errno = C.ENOENT + errno := C.errno + assert errno == C.ENOENT +} -- 2.39.5