Skip to content

generic funtion infers base type for pointers #25208

@Larsimusrex

Description

@Larsimusrex

Describe the bug

When passing a pointer to a generic function, V infers the type to be the non-pointer type instead. e.g. &Foo or &&&Foo are always treated as Foo.

Reproduction Steps

struct Foo {
	a int
}

fn do_generic[T](t T) {
	println(t)
}

fn main() {
	foo := Foo{}
	do_generic(&foo)
}

Expected Behavior

prints

&Foo{
    a: 0
}

Current Behavior

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/test.01K4052GD25C01AZVY60ZTMNJY.tmp.c:5353: error: cannot convert 'struct main__Foo *' to 'struct main__Foo'
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.11

Environment details (OS name and version, etc.)

V full version V 0.4.11 7831fb0.d31aaec
OS linux, "Void Linux"
Processor 12 cpus, 64bit, little endian, AMD Ryzen 5 5600G with Radeon Graphics
Memory 4.07GB/15.52GB
V executable /home/lars/v/v
V last modified time 2025-08-31 09:43:30
V home dir OK, value: /home/lars/v
VMODULES OK, value: /home/lars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/lars
Git version git version 2.50.1
V git status weekly.2025.06-1111-gd31aaecc
.git/config present true
cc version cc (GCC) 14.2.1 20250405
gcc version gcc (GCC) 14.2.1 20250405
clang version clang version 17.0.6
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.3 (a9651ff57165f5710bb09a5fe52590fd6ddb72df)
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

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Generics[T]Bugs/feature requests, that are related to the V generics.Unit: Type SystemBugs/feature requests, that are related to the V types system.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions