mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix auto str for sumtype with alias (#10599)
This commit is contained in:
parent
003f60fc1a
commit
0ac0ab6b4b
@ -221,12 +221,7 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string) {
|
||||
sym := g.table.get_type_symbol(info.parent_type)
|
||||
sym_has_str_method, _, _ := sym.str_method_info()
|
||||
mut parent_str_fn_name := styp_to_str_fn_name(sym.name.replace('.', '__'))
|
||||
if !sym_has_str_method {
|
||||
parent_str_fn_name = g.gen_str_for_type(info.parent_type)
|
||||
}
|
||||
parent_str_fn_name := g.gen_str_for_type(info.parent_type)
|
||||
mut clean_type_v_type_name := util.strip_main_name(styp.replace('__', '.'))
|
||||
g.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto')
|
||||
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0); }')
|
||||
|
9
vlib/v/tests/string_interpolation_sumtype_test.v
Normal file
9
vlib/v/tests/string_interpolation_sumtype_test.v
Normal file
@ -0,0 +1,9 @@
|
||||
type Ints = []int
|
||||
type Strings = []string
|
||||
type Result = Ints | Strings
|
||||
|
||||
fn test_string_interpolation_sumtype() {
|
||||
res := Result(Ints([1, 2, 3]))
|
||||
println(res)
|
||||
assert '$res' == 'Result(Ints([1, 2, 3]))'
|
||||
}
|
Loading…
Reference in New Issue
Block a user