Skip to content

Generic function compilation problem #24570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
get200 opened this issue May 25, 2025 · 1 comment
Open

Generic function compilation problem #24570

get200 opened this issue May 25, 2025 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@get200
Copy link
Contributor

get200 commented May 25, 2025

V version: V 0.4.10 22c327f, press to see full `v doctor` output
V full version V 0.4.10 22c327f
OS windows, Microsoft Windows 11 专业版 Insider Preview 26200 64-bit
Processor 24 cpus, 64bit, little endian, AMD Ryzen 9 5900X 12-Core Processor
Memory 47.94GB/63.91GB
V executable D:\v\v\v.exe
V last modified time 2025-05-24 15:59:38
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-5473-g22c327fe-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 main.v && E:\2025\v\v_test\main.exe

module main

struct Demo[T] {
mut:
	val T
}

type DemoType = int | []DemoType

fn main() {
	decode[Demo[DemoType]]()
	decode[Demo[[]DemoType]]()
}

fn decode[T]() {
	mut typ := T{}
	typ.val = decode_x(typ.val)
}

fn decode_x[T](_ T) T {
	mut field := T{}
	$if T is int {
		field = 0
	} $else $if T is $array {
		field = []DemoType{}
	}
	return field
}

What did you see?

================== C compilation error (from tcc): ==============
cc: C:/Users/Administrator/AppData/Local/Temp/v_0/main.01JW2KG3VWJ79PK76PNFD0DGE2.tmp.c:537: warning: WINVER redefined
cc: C:/Users/Administrator/AppData/Local/Temp/v_0/main.01JW2KG3VWJ79PK76PNFD0DGE2.tmp.c:5859: error: cannot convert 'struct main__DemoType' to 'struct array'
=================================================================
(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 .
VV_LOCAL_SYMBOL void main__decode_T_main__Demo_T_main__DemoType(void) {
	main__Demo_T_main__DemoType typ = ((main__Demo_T_main__DemoType){.val = (main__DemoType){._int=HEAP(int, (0)),._typ=8},});
	typ.val = main__decode_x_T_Array_main__DemoType(typ.val);  // <----- The same function name was generated as a result
}
VV_LOCAL_SYMBOL void main__decode_T_main__Demo_T_Array_main__DemoType(void) {
	main__Demo_T_Array_main__DemoType typ = ((main__Demo_T_Array_main__DemoType){.val = __new_array(0, 0, sizeof(main__DemoType)),});
	typ.val = main__decode_x_T_Array_main__DemoType(typ.val);  // <----- The same function name was generated as a result
}

What did you expect to see?

Compiled successfully

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.

Copy link

Connected to Huly®: V_0.6-22935

@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. labels May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

No branches or pull requests

2 participants