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 returning fixed array type alias as Option #22911

Closed
gechandesu opened this issue Nov 18, 2024 · 0 comments · Fixed by #22912
Closed

C error on returning fixed array type alias as Option #22911

gechandesu opened this issue Nov 18, 2024 · 0 comments · Fixed by #22912
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@gechandesu
Copy link

gechandesu commented Nov 18, 2024

V doctor:

V full version: V 0.4.8 5ec9bb5.a9ae376
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-18 21:13:58

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.46-72-ga9ae3765
.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 fixed_arr_option_return_issue.v

module main

import encoding.binary

type Addr = [4]u8

fn Addr.from_u32(a u32) Addr {
	mut bytes := [4]u8{}
	binary.big_endian_put_u32_fixed(mut bytes, a)
	return Addr(bytes)
}

fn (a Addr) str() string {
	return '${a[0]}.${a[1]}.${a[2]}.${a[3]}'
}

fn (a Addr) u32() u32 {
	return binary.big_endian_u32_fixed(a)
}

struct Net {
	netaddr   Addr
	broadcast Addr
mut:
	h u32
}

fn (mut n Net) next() ?Addr {
	if n.h >= n.broadcast.u32() + 1 {
		return none
	}
	defer {
		n.h++
	}
	return Addr.from_u32(n.h)
}

fn main() {
	net := Net{
		netaddr:   Addr([u8(172), 16, 16, 0]!)
		broadcast: Addr([u8(172), 16, 16, 3]!)
		h:         u32(2886733824)
	}
	for addr in net {
		println(addr)
	}
	// Expected output:
	// 172.16.16.0
	// 172.16.16.1
	// 172.16.16.2
	// 172.16.16.3
}

What did you expect to see?

No compilation errors. This issue may be related to #22910

What did you see instead?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/fixed_arr_option_return_issue.01JD0J512XKSPKATNP2YJA0QB9.tmp.c:14350: warning: cast between pointer and integer of different size
cc: /tmp/v_1000/fixed_arr_option_return_issue.01JD0J512XKSPKATNP2YJA0QB9.tmp.c:14350: error: struct or union expected
... (the original output was 5 lines long, and was truncated to 2 lines)
=================================================================
(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 .

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-21354

@felipensp felipensp self-assigned this Nov 18, 2024
@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants