Skip to content

checker: Variadic option type ...?T incorrectly wraps the implicit array in an outer Option type #28017

Description

@skandhas

Describe the bug

There is a bug in the type checker when handling a combination of variadic arguments and option types (...?T).

Instead of treating the argument internally as a plain array of options ([]?T), the compiler incorrectly wraps the entire implicit array into an outer Option type, resulting in ?[]?T. This causes a compilation failure when passing it to a function expecting []?T.

Reproduction Steps

module main

type Job = fn ()

fn compact(values []?Job) {
	_ := values
}

fn combine(values ...?Job) {
	compact(values)
}

fn main() {
}

Expected Behavior

The code should compile successfully and values ...?Job should be checked inside the function as a plain array []?Job, not an optional array ?[]?Job

Current Behavior

option.v:10:10: error: cannot use `?[]?fn ()` as `[]?fn ()`, it must be unwrapped first in argument 1 to `compact`
    8 |
    9 | fn combine(values ...?Job) {
   10 |     compact(values)
      |             ~~~~~~
   11 | }
   12 |

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.2 a5a89d5

Environment details (OS name and version, etc.)

|V full version      |V 0.5.2 09062b4577f57aa3ca57adb528d751824d8f51a8.a5a89d5
|:-------------------|:-------------------
|OS                  |windows, Microsoft Windows 11 Home 26200 64-bit
|Processor           |16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P
|Memory              |17.6GB/31.58GB
|                    |
|V executable        |D:\sdks\v\v.exe
|V last modified time|2026-08-03 10:50:00
|                    |
|V home dir          |OK, value: D:\sdks\v
|VMODULES            |OK, value: C:\Users\skand\.vmodules
|VTMP                |OK, value: C:\Users\skand\AppData\Local\Temp\v_0
|Current working dir |OK, value: D:\workd\vtools\bug\2
|                    |
|Git version         |git version 2.51.1
|V git status        |a5a89d56
|.git/config present |true
|                    |
|cc version          |cc (Rev3, Built by MSYS2 project) 16.1.0
|gcc version         |gcc (Rev3, Built by MSYS2 project) 16.1.0
|clang version       |clang version 22.1.7 (https://github.com/msys2/MINGW-packages b8f306ad57e0c8f3f15aed0dc809d7e3e8e2eee9)
|msvc version        |N/A
|tcc version         |tcc version 0.9.28rc 2026-07-14_HEAD@d9d02c56* (x86_64 Windows)
|tcc git status      |thirdparty-windows-amd64 f7c7199b-dirty
|emcc version        |N/A
|glibc version       |ldd (cygwin) 3.6.9

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