Skip to content

C code generation error with generic event waiters in discord.v library on V 0.5.1 #27205

@GurlaganSingh

Description

@GurlaganSingh

Describe the bug

Running ./v -g -o vdbg cmd/v && ./vdbg 'main.v' && 'main' on main.v produced a compiler error.

Reproduction Steps

./v -g -o vdbg cmd/v && ./vdbg 'main.v' && 'main'
module main

import discord
import os

fn main() {
	mut bot := discord.bot(os.getenv_opt('DISCORD_BOT_TOKEN') or {
		eprintln('No token specified')
		exit(1)
	}, intents: .message_content | .guild_messages)
	bot.events.on_ready.listen(fn (event discord.ReadyEvent) ! {
		println('Logged as ${event.user.username}! Bot has ${event.guilds.len} guilds')
	})
	bot.events.on_message_create.listen(fn (event discord.MessageCreateEvent) ! {
		if event.message.content != '!ping' {
			return
		}
		event.creator.rest.create_message(event.message.channel_id, content: 'Pong')!
	})
	bot.launch()!
}
### Expected Behavior

**V version:** V 0.5.1
**OS:** Void Linux (glibc)

**What did I do?**
Tried to compile a Discord bot using the `discord.v` library (https://github.com/DarpHome/discord.v) after fixing deprecated `json2.raw_decode()` calls to `json2.decode[json2.Any]()`.

**What did I expect to see?**
Successful compilation and a working Discord bot.

**What did I see instead?**
C compilation error from both tcc and clang backends. The V compiler generates invalid C code when compiling generic event waiters in the discord library.

Steps to reproduce:

  1. v install --git https://github.com/DarpHome/discord.v
  2. Fix src/ directory issue: mv ~/.vmodules/discord/src/*.v ~/.vmodules/discord/ && rmdir ~/.vmodules/discord/src
  3. Fix deprecated json2.raw_decode()json2.decode[json2.Any]() across all .v files
  4. Create minimal bot:
module main

import discord

fn main() {
    mut bot := discord.new_bot(discord.BotConfig{
        token: 'YOUR_TOKEN'
    })!
    bot.run()!
}

### Current Behavior

```bash
/home/lagan/.vmodules/discord/cache.v:191:15: warning: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
  189 |     }
  190 |     mut m2 := unsafe { mut m1[id1] }
  191 |     if id2 !in m1[id1] {
      |                  ~~~~~
  192 |         if sz := max_size2 {
  193 |             if m2.len >= sz {
================== C compilation error (from tcc): ==============
cc: thirdparty/tcc/lib/tcc/include/stdarg.h:8: warning: va_end redefined
cc: /tmp/v_1000/main.01KS538PGMYDWK92AHKGT73F59.tmp.c:94397: error: '{' expected (got ";")
...
cc: /tmp/v_1000/main.01KS538PGMYDWK92AHKGT73F59.tmp.c:94397: error: '{' expected (got ";")
(note: the original output was 17 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.

V version

V 0.5.1 b32f9ab

Environment details (OS name and version, etc.)

|V full version      |V 0.5.1 b32f9abce86304dd09d098f5b58ad89051ab1917
|:-------------------|:-------------------
|OS                  |linux, "Void Linux"
|Processor           |2 cpus, 64bit, little endian, Intel(R) Celeron(R) N4500 @ 1.10GHz
|Memory              |1.15GB/7.61GB
|                    |
|V executable        |/home/lagan/v/v
|V last modified time|2026-05-20 17:09:13
|                    |
|V home dir          |OK, value: /home/lagan/v
|VMODULES            |OK, value: /home/lagan/.vmodules
|VTMP                |OK, value: /tmp/v_1000
|Current working dir |OK, value: /home/lagan/Documents/vbot
|                    |
|Git version         |git version 2.54.0
|V git status        |b32f9abc
|.git/config present |true
|                    |
|cc version          |clang version 21.1.7
|gcc version         |gcc (GCC) 14.2.1 20250405
|clang version       |clang version 21.1.7
|tcc version         |tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
|tcc git status      |thirdparty-linux-amd64 696c1d84
|emcc version        |N/A
|glibc version       |ldd (GNU libc) 2.41

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.

    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