Skip to content

generic function with generic sumtype compile error #25248

@get200

Description

@get200
V version: V 0.4.11 f60d01b, press to see full `v doctor` output
V full version V 0.4.11 3080b41.f60d01b
OS windows, Microsoft Windows 11 专业版 Insider Preview 26200 64-bit
Processor 24 cpus, 64bit, little endian, AMD Ryzen 9 5900X 12-Core Processor
Memory 45.73GB/63.91GB
V executable D:\v\v\v.exe
V last modified time 2025-09-06 14:27:52
V home dir OK, value: D:\v\v
VMODULES OK, value: C:\Users\Administrator.vmodules
VTMP OK, value: C:\Users\Administrator\AppData\Local\Temp\v_0
Current working dir OK, value: E:\2025\v\v_test
Git version git version 2.46.0.windows.1
V git status weekly.2022.48-6002-gf60d01b9-dirty
.git/config present true
cc version cc (Rev5, Built by MSYS2 project) 13.2.0
gcc version gcc (Rev5, Built by MSYS2 project) 13.2.0
clang version clang version 18.1.6
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

What did you do?
./v -g -o vdbg cmd/v && ./vdbg 5.v && E:\2025\v\v_test\5.exe

type DemoType[T] = T | fn () T

pub fn new_state[T](data DemoType[T]) {
	$if T is $function {
		println('function string')
	} $else {
		println('string')
	}
}

fn main() {
	new_state('test string')
	new_state(fn () string {
		return 'function test string'
	})
}

What did you see?

5.v:12:2: error: could not infer generic type `T` in call to `new_state`
   10 | 
   11 | fn main() {
   12 |     new_state('test string')
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   13 |     new_state(fn () string {
   14 |         return 'function test string'
5.v:13:2: error: could not infer generic type `T` in call to `new_state`
   11 | fn main() {
   12 |     new_state('test string')
   13 |     new_state(fn () string {
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   14 |         return 'function test string'
   15 |     })

What did you expect to see?

compile success

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: CheckerBugs/feature requests, that are related to the type checker.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