mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix option map with fn type value (#18849)
This commit is contained in:
parent
c422919481
commit
52a055b6bc
@ -1065,9 +1065,12 @@ fn (mut g Gen) expr_string_surround(prepend string, expr ast.Expr, append string
|
|||||||
// all unified in one place so that it doesnt break
|
// all unified in one place so that it doesnt break
|
||||||
// if one location changes
|
// if one location changes
|
||||||
fn (mut g Gen) option_type_name(t ast.Type) (string, string) {
|
fn (mut g Gen) option_type_name(t ast.Type) (string, string) {
|
||||||
base := g.base_type(t)
|
mut base := g.base_type(t)
|
||||||
mut styp := ''
|
mut styp := ''
|
||||||
sym := g.table.sym(t)
|
sym := g.table.sym(t)
|
||||||
|
if sym.info is ast.FnType {
|
||||||
|
base = 'anon_fn_${g.table.fn_type_signature(sym.info.func)}'
|
||||||
|
}
|
||||||
if sym.language == .c && sym.kind == .struct_ {
|
if sym.language == .c && sym.kind == .struct_ {
|
||||||
styp = '${c.option_name}_${base.replace(' ', '_')}'
|
styp = '${c.option_name}_${base.replace(' ', '_')}'
|
||||||
} else {
|
} else {
|
||||||
@ -1087,6 +1090,9 @@ fn (mut g Gen) result_type_name(t ast.Type) (string, string) {
|
|||||||
}
|
}
|
||||||
mut styp := ''
|
mut styp := ''
|
||||||
sym := g.table.sym(t)
|
sym := g.table.sym(t)
|
||||||
|
if sym.info is ast.FnType {
|
||||||
|
base = 'anon_fn_${g.table.fn_type_signature(sym.info.func)}'
|
||||||
|
}
|
||||||
if sym.language == .c && sym.kind == .struct_ {
|
if sym.language == .c && sym.kind == .struct_ {
|
||||||
styp = '${c.result_name}_${base.replace(' ', '_')}'
|
styp = '${c.result_name}_${base.replace(' ', '_')}'
|
||||||
} else {
|
} else {
|
||||||
|
13
vlib/v/tests/option_map_fn_type_value_test.v
Normal file
13
vlib/v/tests/option_map_fn_type_value_test.v
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const mouse_action_to_function_map = {
|
||||||
|
1: handle_mouse_down_signal
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_mouse_down_signal() string {
|
||||||
|
return 'hello'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_option_map_fn_type_value() {
|
||||||
|
t := mouse_action_to_function_map[1] or { return }
|
||||||
|
println(t())
|
||||||
|
assert t() == 'hello'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user