vlang

/

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

v fmt incorrect behavior with parameter types in struct fn fields #2

Describe the bug

The v fmt command has been behaving incorrectly when formatting function type signatures used as struct fields.

Given the following code:

module main

struct Struct1 {
}

struct Struct2 {
}

struct Struct3 {
    field1 fn (s1 Struct1, s2 Struct2) bool = unsafe { nil }
    field2 Struct1
    field3 Struct2
}

Running v fmt produces:

module main

struct Struct1 {
}

struct Struct2 {
}

struct Struct3 {
        field1 fn (s1 main.Struct1, s2 main.Struct2) bool = unsafe { nil }
        field2 Struct1
        field3 Struct2
}

Additionally, when the module name is not main, the behavior becomes even stranger. For some reason, v fmt uses the project directory name instead of the declared module name.

For example, if the project directory is named any:

module mymod

struct Struct1 {
}

struct Struct2 {
}

struct Struct3 {
    field1 fn (s1 Struct1, s2 Struct2) bool = unsafe { nil }
    field2 Struct1
    field3 Struct2
}

In this case, any.Struct1 and any.Struct2 are generated even though the module is declared as mymod.

module mymod

struct Struct1 {
}

struct Struct2 {
}

struct Struct3 {
        field1 fn (s1 any.Struct1, s2 any.Struct2) bool = unsafe { nil }
        field2 Struct1
        field3 Struct2
}

Reproduction Steps

Simply run v fmt on either of the code examples above.

Expected Behavior

Types that belong to the same module should not be prefixed with the module name.

Current Behavior

Function parameter types are being prefixed with the module name, or in some cases with the project directory name.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.1 05c0a0f

Environment details (OS name and version, etc.)

|V full version |V 0.5.1 3690f882f624c3d82b8c36d38434baf10f68ce4c.05c0a0f |:-------------------|:------------------- |OS |linux, Ubuntu 26.04 LTS (WSL 2) |Processor |6 cpus, 64bit, little endian, AMD Ryzen 5 3500 6-Core Processor |Memory |4.65GB/7.72GB | | |V executable |/home/ericki/v/v |V last modified time|2026-06-16 19:29:04 | | |V home dir |OK, value: /home/ericki/v |VMODULES |OK, value: /home/ericki/.vmodules |VTMP |OK, value: /tmp/v_1000 |Current working dir |OK, value: /home/ericki/any | | |Git version |git version 2.53.0 |V git status |05c0a0fe |.git/config present |true | | |cc version |cc (Ubuntu 15.2.0-16ubuntu1) 15.2.0 |gcc version |gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0 |clang version |Ubuntu clang version 21.1.8 (6ubuntu1) |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 (Ubuntu GLIBC 2.43-2ubuntu2) 2.43

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