Skip to content

cgen error for generic fn with mut x ?Type argument, when an array is passed #24101

@spytheman

Description

@spytheman
V version: V 0.4.10 a8a4507, press to see full `v doctor` output
V full version V 0.4.10 dd083e7.a8a4507
OS linux, Ubuntu 20.04.6 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
Memory 4.84GB/15.05GB
V executable /home/delian/v/v
V last modified time 2025-04-01 11:15:55
V home dir OK, value: /home/delian/v
VMODULES OK, value: /home/delian/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/delian/v
env VFLAGS "-no-parallel"
Git version git version 2.48.1
V git status weekly.2025.13-40-ga8a45072
.git/config present true
cc version cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
gcc version gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
clang version clang version 10.0.0-4ubuntu1
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 (Ubuntu GLIBC 2.31-0ubuntu9.16) 2.31

What did you do?
./v -g -o vdbg cmd/v && ./vdbg xx.v && xx

fn main() {
	mut arr := []int{}
	mut bbb := unwrap(mut arr)
	bbb << 1
	dump(bbb)
}
fn unwrap[T](mut t ?T) T {
	return t or { panic('unexpected `none`') }
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/xx.01JQRH1JDP41ZXN4HD3KAKE80K.tmp.c:6008: error: cannot convert 'struct array *' to 'struct _option_Array_int_ptr'
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).

What did you expect to see?

a compiled program

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.Generics[T]Bugs/feature requests, that are related to the V generics.Option TypeBugs/feature requests, that are related to `?Type`.Unit: CompilerBugs/feature requests, that are related to the V compiler in general.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions