Skip to content

[Compiler Bug] $dbg outside of a function generates invalid C #27682

Description

@HuntedByTheIRS
V version: V 0.5.1, press to see full `v doctor` output
V full version V 0.5.1 0c3183c
OS linux, "EndeavourOS Linux"
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memory 3.27GB/19.29GB
V executable /usr/lib/vlang/v
V last modified time 2026-07-04 08:19:04
V home dir NOT writable, value: /usr/lib/vlang
VMODULES OK, value: /home/specter/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/specter/Templates/vtest
Git version git version 2.55.0
V git status N/A
.git/config present false
cc version cc (GCC) 16.1.1 20260625
gcc version gcc (GCC) 16.1.1 20260625
clang version clang version 22.1.6
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status Error: fatal: detected dubious ownership in repository at '/usr/lib/vlang/thirdparty/tcc'
To add an exception for this directory, call:
git config --global --add safe.directory /usr/lib/vlang/thirdparty/tcc

Error: fatal: detected dubious ownership in repository at '/usr/lib/vlang/thirdparty/tcc'
To add an exception for this directory, call:

git config --global --add safe.directory /usr/lib/vlang/thirdparty/tcc

|emcc version |N/A
|glibc version |ldd (GNU libc) 2.43

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

$dbg;

fn main() {
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01KWX5Z3YJP3CPNTETTR4DQY9F.tmp.c:9734: error: declaration expected
=================================================================
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. 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?

I expected a compiler error.

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

    No labels
    No labels

    Type

    No type

    Fields

    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