Skip to content

C error on fixed array init in if expression #24082

Description

@gechandesu
V version: V 0.4.10 6b3521f, press to see full `v doctor` output
V full version V 0.4.10 89d1aac.6b3521f
OS linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P
Memory 4.22GB/15.35GB
V executable /home/ge/.vlang/v
V last modified time 2025-03-29 12:43:00
V home dir OK, value: /home/ge/.vlang
VMODULES OK, value: /home/ge/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/ge
Git version git version 2.49.0
V git status weekly.2025.08-257-g6b3521f5
.git/config present true
cc version cc (GCC) 14.2.1 20250207
gcc version gcc (GCC) 14.2.1 20250207
clang version clang version 19.1.7
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (GNU libc) 2.41

What did you do?
./v -g -o vdbg cmd/v && ./vdbg /tmp/fixed_arrays_in_if_expr.v && /tmp/fixed_arrays_in_if_expr

fn main() {
	arr := [u8(1), 2, 3, 4]!
	if arr != [4]u8{} || arr != [4]u8{init: 255} { // OK
		println('success')
	}
	if arr !in [[4]u8{}, [4]u8{init: 255}] { // Compilation failed with C error
		println('success')
	}
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/fixed_arrays_in_if_expr.01JQH0FAP821SYQYN0P557AC13.tmp.c:5392: error: expression expected before '{'
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

More verbose:

~ $ v -show-c-output run /tmp/fixed_arrays_in_if_expr.v
======== Output of the C Compiler (/home/ge/.vlang/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/fixed_arrays_in_if_expr.01JQH0GDPNNVV74N5V6K1C2CTW.tmp.c:5392: error: expression expected before '{'
===================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/fixed_arrays_in_if_expr.01JQH0GDPNNVV74N5V6K1C2CTW.tmp.c: In function ‘main__main’:
/tmp/v_1000/fixed_arrays_in_if_expr.01JQH0GDPNNVV74N5V6K1C2CTW.tmp.c:5392:22: error: expected expression before ‘{’ token
 5392 |         if (!(arr == {0} || arr == {255, 255, 255, 255})) {
      |                      ^
===============================================
No such file or directory; code: 2

What did you expect to see?

No C errors

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions