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: when flag is imported and a const is used as default value in struct #23909

Open
larpon opened this issue Mar 11, 2025 · 2 comments · May be fixed by #23933
Open

C error: when flag is imported and a const is used as default value in struct #23909

larpon opened this issue Mar 11, 2025 · 2 comments · May be fixed by #23933
Labels
Bug This tag is applied to issues which reports bugs. Unit: markused Bugs/feature requests, that are related to the -skip-unused.

Comments

@larpon
Copy link
Contributor

larpon commented Mar 11, 2025

V version: V 0.4.9 4cc6f25, press to see full `v doctor` output
V full version V 0.4.9 89d1aac.4cc6f25
OS linux, "EndeavourOS Linux"
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 8845HS w/ Radeon 780M Graphics
Memory 13.3GB/30.64GB
V executable /home/lmp/Projects/v/v
V last modified time 2025-03-11 08:11:28
V home dir OK, value: /home/lmp/Projects/v
VMODULES OK, value: /home/lmp/.vmodules
VTMP OK, value: /dev/shm
Current working dir OK, value: /home/lmp/Projects/v
Git version git version 2.48.1
V git status weekly.2025.11-2-g4cc6f254 (3 commit(s) behind V master)
.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 shared:INFO: old sanity: 4.0.3-git
glibc version ldd (GNU libc) 2.41

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

module main

import flag

const c_default_port = u16(12345)

struct Options {
	headless bool
	port     u16 = c_default_port @[short: p]
}

fn main() {
	args := arguments()
	_, _ := flag.to_struct[Options](args, style: .v, skip: 1)!
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /dev/shm/t.01JP2QZNKWBQS2M3NH32QF2VR5.tmp.c:8982: error: '_const_main__c_default_port' undeclared
=================================================================
(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 .

What did you expect to see?

A clean compile and run

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.

@larpon larpon added the Bug This tag is applied to issues which reports bugs. label Mar 11, 2025
Copy link

Connected to Huly®: V_0.6-22311

@larpon
Copy link
Contributor Author

larpon commented Mar 11, 2025

Running the same file with -no-skip-unused works

@larpon larpon added the Unit: markused Bugs/feature requests, that are related to the -skip-unused. label Mar 11, 2025
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. Unit: markused Bugs/feature requests, that are related to the -skip-unused.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant