Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C error on appending aliased fixed arrays into array of sumtype #23009

Open
gechandesu opened this issue Nov 29, 2024 · 1 comment
Open

C error on appending aliased fixed arrays into array of sumtype #23009

gechandesu opened this issue Nov 29, 2024 · 1 comment

Comments

@gechandesu
Copy link

gechandesu commented Nov 29, 2024

V doctor:

V full version: V 0.4.8 5ec9bb5.f2c281e
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

getwd: /home/ge/Code/v/netaddr
vexe: /home/ge/.vlang/v
vexe mtime: 2024-11-29 19:48:59

vroot: OK, value: /home/ge/.vlang
VMODULES: OK, value: /home/ge/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1
Git vroot status: weekly.2024.47-62-gf2c281ea
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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

module main

type IPv4 = [4]u8
type IPv6 = [16]u8
type IP = IPv4 | IPv6

fn main() {
	mut arr := []IP{}
	arr << IPv4([4]u8{})
	arr << IPv6([16]u8{})
	println(arr)
}

What did you expect to see?

Something like [IP([0, 0, 0, 0]), IP([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])] or some V error since the following variant works (but not as expected, see output):

module main

type IPv4 = [4]u8
type IPv6 = [16]u8
type IP = IPv4 | IPv6

fn main() {
	mut arr := []IP{}
	arr << IP(IPv4([4]u8{}))
	arr << IP(IPv6([16]u8{}))
	println(arr)
}
// Output: [IP(IPv4([72, 0, 0, 0])), IP(IPv6([248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))]

Note: only zeros is expected in output, but fixed arrays have random non-zero first item. This is also bug.

What did you see instead?

[unknown sum type value, unknown sum type value]

C error will shown only if -show-c-output is passed:

$ v -show-c-output run aliased_fixed_arrays_array.v
======== Output of the C Compiler (/home/ge/.vlang/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13871: error: too many initializers
===================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c: In function ‘main__main’:
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13871:60: warning: excess elements in struct initializer
13871 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0} }));
      |                                                            ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13871:60: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13871:63: warning: excess elements in struct initializer
13871 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0} }));
      |                                                               ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13871:63: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:60: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                            ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:60: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:63: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                               ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:63: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:66: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                  ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:66: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:69: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                     ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:69: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:72: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                        ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:72: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:75: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                           ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:75: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:78: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                              ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:78: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:81: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                 ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:81: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:84: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                    ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:84: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:87: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                       ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:87: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:90: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                          ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:90: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:93: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                             ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:93: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:96: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                                ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:96: note: (near initialization for ‘(anonymous)[0]’)
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:99: warning: excess elements in struct initializer
13872 |         array_push((array*)&arr, _MOV((main__IP[]){ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }));
      |                                                                                                   ^
/tmp/v_1000/aliased_fixed_arrays_array.01JDWR1SZD1QKEY4X09ETJSN4V.tmp.c:13872:99: note: (near initialization for ‘(anonymous)[0]’)
===============================================
[unknown sum type value, unknown sum type value]

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.

Huly®: V_0.6-21450

@jorgeluismireles
Copy link

Is weird this works:

type IP = [4]u8 | [16]u8

fn main() {
	mut arr := []IP{}
	arr << [u8(0),0,0,0]!
	arr << [u8(0),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]!
	println(arr)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants