mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: fix missing 'optional' and 'result' in type name and cname of map (#16047)
This commit is contained in:
@ -982,7 +982,8 @@ pub fn (t &Table) thread_name(return_type Type) string {
|
|||||||
return_type_sym := t.sym(return_type)
|
return_type_sym := t.sym(return_type)
|
||||||
ptr := if return_type.is_ptr() { '&' } else { '' }
|
ptr := if return_type.is_ptr() { '&' } else { '' }
|
||||||
opt := if return_type.has_flag(.optional) { '?' } else { '' }
|
opt := if return_type.has_flag(.optional) { '?' } else { '' }
|
||||||
return 'thread $opt$ptr$return_type_sym.name'
|
res := if return_type.has_flag(.result) { '!' } else { '' }
|
||||||
|
return 'thread $opt$res$ptr$return_type_sym.name'
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
@ -996,8 +997,9 @@ pub fn (t &Table) thread_cname(return_type Type) string {
|
|||||||
}
|
}
|
||||||
return_type_sym := t.sym(return_type)
|
return_type_sym := t.sym(return_type)
|
||||||
suffix := if return_type.is_ptr() { '_ptr' } else { '' }
|
suffix := if return_type.is_ptr() { '_ptr' } else { '' }
|
||||||
prefix := if return_type.has_flag(.optional) { '_option_' } else { '' }
|
opt := if return_type.has_flag(.optional) { '_option_' } else { '' }
|
||||||
return '__v_thread_$prefix$return_type_sym.cname$suffix'
|
res := if return_type.has_flag(.result) { '_result_' } else { '' }
|
||||||
|
return '__v_thread_$opt$res$return_type_sym.cname$suffix'
|
||||||
}
|
}
|
||||||
|
|
||||||
// map_source_name generates the original name for the v source.
|
// map_source_name generates the original name for the v source.
|
||||||
@ -1007,7 +1009,9 @@ pub fn (t &Table) map_name(key_type Type, value_type Type) string {
|
|||||||
key_type_sym := t.sym(key_type)
|
key_type_sym := t.sym(key_type)
|
||||||
value_type_sym := t.sym(value_type)
|
value_type_sym := t.sym(value_type)
|
||||||
ptr := if value_type.is_ptr() { '&' } else { '' }
|
ptr := if value_type.is_ptr() { '&' } else { '' }
|
||||||
return 'map[$key_type_sym.name]$ptr$value_type_sym.name'
|
opt := if value_type.has_flag(.optional) { '?' } else { '' }
|
||||||
|
res := if value_type.has_flag(.result) { '!' } else { '' }
|
||||||
|
return 'map[$key_type_sym.name]$opt$res$ptr$value_type_sym.name'
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
@ -1015,7 +1019,9 @@ pub fn (t &Table) map_cname(key_type Type, value_type Type) string {
|
|||||||
key_type_sym := t.sym(key_type)
|
key_type_sym := t.sym(key_type)
|
||||||
value_type_sym := t.sym(value_type)
|
value_type_sym := t.sym(value_type)
|
||||||
suffix := if value_type.is_ptr() { '_ptr' } else { '' }
|
suffix := if value_type.is_ptr() { '_ptr' } else { '' }
|
||||||
return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix
|
opt := if value_type.has_flag(.optional) { '_option_' } else { '' }
|
||||||
|
res := if value_type.has_flag(.result) { '_result_' } else { '' }
|
||||||
|
return 'Map_${key_type_sym.cname}_$opt$res$value_type_sym.cname$suffix'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int {
|
pub fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int {
|
||||||
|
13
vlib/v/fmt/tests/map_value_with_optional_result_expected.vv
Normal file
13
vlib/v/fmt/tests/map_value_with_optional_result_expected.vv
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
struct Foo {
|
||||||
|
map1 map[string]!string
|
||||||
|
map2 map[string]?string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
map1 := map[string]!string{}
|
||||||
|
map2 := map[string]?string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(arg map[string]?string) ?string {
|
||||||
|
return arg['akey']
|
||||||
|
}
|
13
vlib/v/fmt/tests/map_value_with_optional_result_input.vv
Normal file
13
vlib/v/fmt/tests/map_value_with_optional_result_input.vv
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
struct Foo {
|
||||||
|
map1 map[string]!string
|
||||||
|
map2 map[string]?string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
map1 := map[string]!string{}
|
||||||
|
map2 := map[string]?string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(arg map[string]?string) ?string {
|
||||||
|
return arg['akey']
|
||||||
|
}
|
@ -13,3 +13,17 @@ fn test_map_value_with_optional_result() {
|
|||||||
fn foo(arg map[string]?string) ?string {
|
fn foo(arg map[string]?string) ?string {
|
||||||
return arg['akey']
|
return arg['akey']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
map1 map[string]!string
|
||||||
|
map2 map[string]?string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar() {
|
||||||
|
map1 := map[string]?string{}
|
||||||
|
map2 := map[string]!string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz(arg map[string]?string) ?string {
|
||||||
|
return arg['akey']
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user