mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: fix sumtype custom str (#6534)
This commit is contained in:
parent
1ddf46f3c6
commit
8e8e808fc9
@ -383,16 +383,13 @@ fn struct_auto_str_func(sym table.TypeSymbol, field_type table.Type, fn_name, fi
|
||||
}
|
||||
if has_custom_str {
|
||||
return '${fn_name}($obj)'
|
||||
} else {
|
||||
return 'indent_${fn_name}($obj, indent_count + 1)'
|
||||
}
|
||||
} else if sym.kind in [.array, .array_fixed, .map] {
|
||||
return 'indent_${fn_name}($obj, indent_count + 1)'
|
||||
} else if sym.kind in [.array, .array_fixed, .map, .sum_type] {
|
||||
if has_custom_str {
|
||||
return '${fn_name}(it->${c_name(field_name)})'
|
||||
}
|
||||
return 'indent_${fn_name}(it->${c_name(field_name)}, indent_count + 1)'
|
||||
} else if sym.kind == .sum_type {
|
||||
return 'indent_${fn_name}(it->${c_name(field_name)}, indent_count + 1)'
|
||||
} else {
|
||||
mut method_str := 'it->${c_name(field_name)}'
|
||||
if sym.kind == .bool {
|
||||
|
@ -57,3 +57,21 @@ fn test_pointer() {
|
||||
st := ST(0)
|
||||
assert '${&st}' == '&ST(0)'
|
||||
}
|
||||
|
||||
struct Xyz {}
|
||||
|
||||
type Hola = Abc | Xyz
|
||||
|
||||
fn (h Hola) str() string {
|
||||
return 'Hola'
|
||||
}
|
||||
|
||||
struct HolaContainer {
|
||||
h Hola
|
||||
}
|
||||
|
||||
fn test_custom_str_method() {
|
||||
h := HolaContainer{}
|
||||
assert h.str() == 'HolaContainer {\n h: Hola\n}'
|
||||
assert '$h' == 'HolaContainer {\n h: Hola\n}'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user