Skip to content

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

Description

@larpon
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Unit: markusedBugs/feature requests, that are related to the -skip-unused.

    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