You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When declaring function types in submodules, C code generation sometimes doesn't work out properly, when trying to declare the type in the V type definitions section. I cannot get this to happen in the main module, but is easily reproducible in a submodule.
Funnily enough, if I remove the result from the return types of the functions, I get a different C-compiler error.
Bonus bug: If you remove all the result indicators, you get a whole different set of errors.
Expected Behavior
I expect the program to compile
Current Behavior
Output when compiling WITH result types:
v . -show-c-output
======== Output of the C Compiler (/home/sukus/v/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/bruh.01K9K36M83HT1EHS0XCBXYC524.tmp.c:660: error: identifier expected
=================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/bruh.01K9K36M83HT1EHS0XCBXYC524.tmp.c:660:38: error: expected declaration specifiers or ‘...’ before ‘*’ token
660 | typedef _v__result_Array_fixed_u8_4 (*not_main__CallbackType)();
| ^
===============================================
Output when compiling WITHOUT result types:
v . -show-c-output
======== Output of the C Compiler (/home/sukus/v/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/bruh.01K9K3AKQD81KSBV7NJFRQBBJN.tmp.c:4589: error: lvalue expected
=================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/bruh.01K9K3AKQD81KSBV7NJFRQBBJN.tmp.c:896:60: error: ‘callback’ declared as function returning an array
896 | VV_LOC void not_main__callback_consumer(Array_fixed_u8_4 (*callback)());
| ^~~~~~~~
/tmp/v_1000/bruh.01K9K3AKQD81KSBV7NJFRQBBJN.tmp.c:4588:60: error: ‘callback’ declared as function returning an array
4588 | VV_LOC void not_main__callback_consumer(Array_fixed_u8_4 (*callback)(void)) {
| ^~~~~~~~
/tmp/v_1000/bruh.01K9K3AKQD81KSBV7NJFRQBBJN.tmp.c: In function ‘not_main__callback_consumer’:
/tmp/v_1000/bruh.01K9K3AKQD81KSBV7NJFRQBBJN.tmp.c:4589:19: error: request for member ‘ret_arr’ in something not a structure or union
4589 | callback().ret_arr;
| ^
===============================================
Possible Solution
I experimented a bit and found a potential solution to the issue when compiling WITH result types. However, I don't know if this is the correct solution, and have not looked that far into how the V -> C compilation pipeline works, so it might be a long shot: https://github.com/sukus21/v/commit/3f1c6fb9f767ad604f086f9a4b234554a1443b51
|V full version |V 0.4.12 af62364a29312a09f76aa9ad3f734790e534c162
|:-------------------|:-------------------
|OS |linux, Debian GNU/Linux 12 (bookworm) (VM)
|Processor |2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
|Memory |1.09GB/2.02GB
| |
|V executable |/home/admin/v/v
|V last modified time|2025-11-09 00:25:30
| |
|V home dir |OK, value: /home/admin/v
|VMODULES |OK, value: .vmodules
|VTMP |OK, value: /tmp/v_0
|Current working dir |OK, value: /home/admin/playground
| |
|Git version |git version 2.39.5
|V git status |N/A
|.git/config present |true
| |
|cc version |cc (Debian 12.2.0-14+deb12u1) 12.2.0
|gcc version |gcc (Debian 12.2.0-14+deb12u1) 12.2.0
|clang version |Debian clang version 14.0.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 '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:
git config --global --add safe.directory /home/admin/v/thirdparty/tcc
Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:
git config --global --add safe.directory /home/admin/v/thirdparty/tcc
|emcc version |N/A
|glibc version |ldd (Debian GLIBC 2.36-9+deb12u10) 2.36
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.
Describe the bug
When declaring function types in submodules, C code generation sometimes doesn't work out properly, when trying to declare the type in the
V type definitionssection. I cannot get this to happen in themainmodule, but is easily reproducible in a submodule.Funnily enough, if I remove the result from the return types of the functions, I get a different C-compiler error.
Reproduction Steps
Bonus bug: If you remove all the result indicators, you get a whole different set of errors.
Expected Behavior
I expect the program to compile
Current Behavior
Output when compiling WITH result types:
Output when compiling WITHOUT result types:
Possible Solution
I experimented a bit and found a potential solution to the issue when compiling WITH result types. However, I don't know if this is the correct solution, and have not looked that far into how the V -> C compilation pipeline works, so it might be a long shot: https://github.com/sukus21/v/commit/3f1c6fb9f767ad604f086f9a4b234554a1443b51
Additional Information/Context
No response
V version
V 0.4.12 af62364
Environment details (OS name and version, etc.)
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.