Skip to content

Cannot test for void return_type #24391

@rosshadden

Description

@rosshadden

Describe the bug

You seem to be unable to test whether a FunctionData#return_type is void.

Reproduction Steps

struct Struct {}

fn (s Struct) func() {}

fn main() {
	$for method in Struct.methods {
		println('${method.name}: ${method.return_type}')

		$if method.return_type {
			println('this runs but it is true regardless of the return type')
		}
		$if method.return_type is ? {
			println('this never runs but I think it should')
		}
		$if method.return_type !is ? {
			println('this never runs either and that makes sense')
		}
		$if method.return_type == 1 {
			println('this runs which is kind of expected')
		}
		$if method.return_type == 2 {
			println('this runs too which is REALLY WEIRD')
		}
	}
}
$ v run .
func: 1
this runs but it is true regardless of the return type
this runs which is kind of expected
this runs too which is REALLY WEIRD

Expected Behavior

Based on this I think method.return_type is void should be a test that works, or at least is ? which is what the compiler yells at you into using.

I also don't understand why return_type is true when compared against any integer. It should either work as expected with return_type == 1 working in this case (and == 42 being made to not work), or if that was never intended than no integer comparison should pass.

This should probably be the output of the above example:

$ v run .
func: 1
this runs but it is true regardless of the return type
this never runs but I think it should
this runs which is kind of expected

Current Behavior

  • return_type is void says to "use ? instead of ?void"
  • return_type is ?void says the same
  • return_type is ? compiles but does not pass
  • return_type == 1 is a false positive, because it turns out comparing return_type to any int passes

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 875c165

Environment details (OS name and version, etc.)

V full version V 0.4.10 b76b1ee.875c165
OS linux, "Artix Linux"
Processor 32 cpus, 64bit, little endian, AMD Ryzen 9 7950X3D 16-Core Processor
Memory 4.14GB/62GB
V executable /home/ross/x/v/v
V last modified time 2025-05-02 14:46:13
V home dir OK, value: /home/ross/x/v
VMODULES OK, value: /home/ross/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /tmp/ciea
Git version git version 2.49.0
V git status weekly.2025.17-39-g875c1654
.git/config present true
cc version cc (GCC) 14.2.1 20250207
gcc version gcc (GCC) 14.2.1 20250207
clang version clang version 19.1.7
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 (GNU libc) 2.41

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

Labels

BugThis tag is applied to issues which reports bugs.ComptimeFeatures processed during compile time, like $if, $for, $env etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions