Skip to content

C declarations imported from an external module cannot be used for casting #26192

@revosw

Description

@revosw

Describe the bug

When a C type declaration is declared in the same module as you are running with v run ., you may cast a value to that C type. However, when the same type is declared in an external module and you import that module, you get

main.v:5:15: error: unknown function: C.TEST
    3 |
    4 | fn main() {
    5 |     println(C.TEST(0))
      |               ~~~~~~~
    6 | }
main.v:5:5: error: `println` can not print void expressions
    3 |
    4 | fn main() {
    5 |     println(C.TEST(0))
      |     ~~~~~~~~~~~~~~~~~~
    6 | }

Reproduction Steps

Initialize a brand new project with v init
Create a new main.c.v file with the contents:

module main

type C.TEST = int

Now edit main.v to use the type

module main

fn main() {
    println(C.TEST(0))
}

Notice that this works exactly as intended.

Now create a new folder ./mymodule and v init inside. Then move main.c.v from the parent module to mymodule, rename it to mod.c.v and replace the contents with:

module mymodule

pub type C.TEST = int

Rename mymodule/main.v to mymodule/mod.v, then change mymodule/mod.v to only contain

module mymodule

Expected Behavior

Instead of an error saying "unknown function", casting should just work like locally declared C types

Current Behavior

Compilation fails with error

main.v:5:15: error: unknown function: C.TEST
    3 |
    4 | fn main() {
    5 |     println(C.TEST(0))
      |               ~~~~~~~
    6 | }
main.v:5:5: error: `println` can not print void expressions
    3 |
    4 | fn main() {
    5 |     println(C.TEST(0))
      |     ~~~~~~~~~~~~~~~~~~
    6 | }

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 21a0f11

Environment details (OS name and version, etc.)

V full version V 0.4.12 cd035e2.21a0f11
OS windows, Microsoft Windows 11 Pro 22000 64-bit
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Memory 2.88GB/7.41GB
V executable C:\dev_tools\v\v.exe
V last modified time 2025-12-28 12:49:02
V home dir OK, value: C:\dev_tools\v
VMODULES OK, value: C:\Users\bruker.vmodules
VTMP OK, value: C:\Users\bruker\AppData\Local\Temp\v_0
Current working dir OK, value: C:\dev\v\trash\ccast
Git version git version 2.36.1.windows.1
V git status weekly.2023.52-4284-g21a0f111
.git/config present true
cc version N/A
gcc version N/A
clang version N/A
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions