vlang

/

v Public
0 commits 39 issues 0 pull requests 0 contributors Discussions Projects CI

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: error: 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).
builder error: 
==================
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      |V 0.5.1 ddb021b9866c3b4523b746fa2f4c16a594f8bd89.2ef6610
|:-------------------|:-------------------
|OS                  |windows, Њ ©Єа®б®дв Windows 10 „®¬ и­пп 19045 64-а §ап¤­ п
|Processor           |4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz  
|Memory              |5.11GB/15.96GB
|                    |
|V executable        |D:\langs\v\v.exe
|V last modified time|2026-06-15 08:34:09
|                    |
|V home dir          |OK, value: D:\langs\v
|VMODULES            |OK, value: C:\Users\User\.vmodules
|VTMP                |OK, value: e:\Temp\Win10Temp\v_0
|Current working dir |OK, value: D:\langs\__works_v\sudeng
|                    |
|Git version         |git version 2.47.1.windows.2
|V git status        |0.5.1-1909-g2ef6610a
|.git/config present |true
|                    |
|cc version          |N/A
|gcc version         |gcc (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders, r1) 15.1.0
|clang version       |clang version 20.1.0
|msvc version        |ЋЇвЁ¬Ё§ЁагойЁ© Є®¬ЇЁ«пв®а Microsoft (R) C/C++ ўҐабЁЁ 19.43.34808 ¤«п x64
|tcc version         |tcc version 0.9.27 (x86_64 Windows)
|tcc git status      |N/A
|emcc version        |N/A
|glibc version       |N/A

[!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.