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

Returning fixed size arrays is still making C errors, even with the size being a normal int #22058

Closed
Checkmate6659 opened this issue Aug 16, 2024 · 2 comments · Fixed by #22059
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc 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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@Checkmate6659
Copy link

Checkmate6659 commented Aug 16, 2024

V doctor:

V full version: V 0.4.7 f879368.38e23a7
OS: linux, Ubuntu 20.04.6 LTS
Processor: 8 cpus, 64bit, little endian, AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx

getwd: /home/enigma/vlang/bober_mini
vexe: /home/enigma/vlang/v/v
vexe mtime: 2024-08-16 09:02:57

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

Git version: git version 2.25.1
Git vroot status: weekly.2024.33-12-g38e23a76
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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

module board

pub const n = 7
pub const nsq = n*n //can't be u16 because otherwise C error (BUG)

//Return an empty board.
pub fn empty_board(/*mut b [nsq]u8*/) [nsq]u8
{
	/* for i in 0..nsq
	{
		b[i] = 0
	} */
	return [nsq]u8{init: 0}
}

//Clear screen.
pub fn clear_screen()
{
	print("\033[2J\033[1;1H")
}

// pub const nsq = 49

// pub fn empty_board(mut b [nsq]u8) {
//         for i in 0 .. nsq {
//                 b[i] = 0
//         }
// }

What did you expect to see?

Still a function that returns a fixed size u8 array with 49 zeroes in it. We've established that nsq being a u16 breaks everything, but somehow even without that there is a bug. At least I can initialize my array by making it mutable and passing it in as an argument.

What did you see instead?

src/board.v:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
    1 | module board
      | ^
    2 | 
    3 | pub const n = 7

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.

@spytheman
Copy link
Member

It is reproducible with v -shared ww.v .

@spytheman spytheman added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Comptime Features processed during compile time, like $if, $for, $env etc Bug This tag is applied to issues which reports bugs. labels Aug 16, 2024
@spytheman
Copy link
Member

spytheman commented Aug 16, 2024

Possible duplicate of #22057 .

The same workaround works for the example here: return [nsq]u8{}, but since return nodes are different, not sure if the same fix will work for both cases.

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. Comptime Features processed during compile time, like $if, $for, $env etc 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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants