Incorrect C code generating, I think... #4
Describe the bug
Running ./v -g -o vdbg cmd/v && ./vdbg "main.v" && "D:\langs\__works_v\sudeng\main.exe" on main.v produced a compiler error.
Reproduction Steps
./v -g -o vdbg cmd/v && ./vdbg "main.v" && "D:\langs\__works_v\sudeng\main.exe"
module main
import bitset as bs
import sudeng as se
/////////////////////////////////////////////////////////////
// pub struct BitSet[T] {
// mut:
// bits T
// index int = -1
// }
// // set sets variadic number of bits in a bitset, returns true on success
// pub fn (mut b BitSet[T]) set(bits ...T) bool {
// for bit in bits {
// if bit = sizeof(T)*8 { return false }
// b.bits |= 1 << bit
// }
// return true
// }
// clear sets all bits in a bitset
// pub fn (mut b BitSet[T]) set_all() bool {
// mut mask := T(0)
// mask = match sizeof(T) {
// 1 { 0xFF }
// 2 { 0xFFFF }
// 4 { 0xFFFFFFFF }
// 8 { 0xFFFFFFFFFFFFFFFF }
// else { return false }
// }
// b.bits |= T(mask)
// return true
// }
/////////////////////////////////////////////////////////////
pub type Candidates = bs.BitSet[u32]
pub fn cand_full() Candidates {
mut cands := Candidates{}
cands.set_all()
return cands
}
// pub fn (mut cands Candidates) set(digits ...int) {
// cands.set(digits)
// }
/////////////////////////////////////////////////////////////
fn main() {
mut ba := bs.BitSet[u32]{}
dump(ba)
ba.set_all()
dump(ba)
mut cands := se.Candidates{}
dump(cands)
// cands = cand_full()
// // cs.set(1)
// dump(cands)
}
Expected Behavior
"[D:\langs\__works_v\sudeng\main.v:57] cands: Candidates(BitSet{ bits: 0, len: 0, count: 0 })"
Current Behavior
================== C compilation error (from tcc): ==============
cc: E://Temp//WIN10T~1//v_0//MA6914~1.C:9253: warning: implicit declaration of function 'sudeng__Candidates_set_T_u32'
cc: tcc: [31merror:[39m undefined symbol 'sudeng__Candidates_set_T_u32'
...
cc: tcc: error: undefined symbol 'sudeng__Candidates_set_T_u32'
(note: the original output was 9 lines long; it was truncated to its first 2 lines + the last line)
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
[1m[31mbuilder error[39m[22m:
==================
C error found while compiling generated C code.
This can be caused by invalid C interop code, C compiler flags, or a V compiler bug.
If your code is pure V and this still happens, 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 .
Possible Solution
No response
Additional Information/Context
Generated by v bug from main.v.
Change this
mut cands := se.Candidates{}
to this
mut cands := Candidates{}
and it works as expected.
V version
V 0.5.1 2ef6610
Environment details (OS name and version, etc.)
|V full version |[1mV 0.5.1 ddb021b9866c3b4523b746fa2f4c16a594f8bd89.2ef6610[22m
|:-------------------|[1m:-------------------[22m
|OS |[1mwindows, Њ ©Єа®б®дв Windows 10 „®¬ ипп 19045 64-а §ап¤ п[22m
|Processor |[1m4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz [22m
|Memory |[1m5.11GB/15.96GB[22m
| |[1m[22m
|V executable |[1mD:\langs\v\v.exe[22m
|V last modified time|[1m2026-06-15 08:34:09[22m
| |[1m[22m
|V home dir |[1mOK[22m, value: [1mD:\langs\v[22m
|VMODULES |[1mOK[22m, value: [1mC:\Users\User\.vmodules[22m
|VTMP |[1mOK[22m, value: [1me:\Temp\Win10Temp\v_0[22m
|Current working dir |[1mOK[22m, value: [1mD:\langs\__works_v\sudeng[22m
| |[1m[22m
|Git version |[1mgit version 2.47.1.windows.2[22m
|V git status |[1m0.5.1-1909-g2ef6610a[22m
|.git/config present |[1mtrue[22m
| |[1m[22m
|cc version |[1mN/A[22m
|gcc version |[1mgcc (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders, r1) 15.1.0[22m
|clang version |[1mclang version 20.1.0[22m
|msvc version |[1mЋЇвЁ¬Ё§ЁагойЁ© Є®¬ЇЁ«пв®а Microsoft (R) C/C++ ўҐабЁЁ 19.43.34808 ¤«п x64[22m
|tcc version |[1mtcc version 0.9.27 (x86_64 Windows)[22m
|tcc git status |[1mN/A[22m
|emcc version |[1mN/A[22m
|glibc version |[1mN/A[22m
[!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.