vlang/v

cgen error produced for assigning a cast of an optional fn type value

Closed this issue · 0 comments

V doctor:

V full version: V 0.4.7 6eae77b.986e9cf
OS: linux, Ubuntu 20.04.6 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-09-22 17:41:50

vroot: OK, value: /space/v/oo
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.0
Git vroot status: weekly.2024.37-39-g986e9cfa (11 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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

type DataFn = fn (name string) string
fn which_lang(name string) string { return name }
fn find_func(name string) ?DataFn {
	a := ?DataFn( which_lang )
	return a
}

What did you expect to see?

a compiled program

What did you see instead?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/casting_to_option_fn_type.01J8DDTJSFMBFC615NHX9GES1K.tmp.c:13348: error: cannot convert 'struct _option_anon_fn_string__string' to 'struct string (*)(struct string)'
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).

Note: discovered while testing #22280 , I am not sure, if it is directly related or another bug.

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.