@@ -56,7 +56,11 @@ fn (mut g Gen) get_str_fn(typ ast.Type) string {
56
56
$if trace_autostr ? {
57
57
eprintln ('> get_str_fn: ${typ.debug()} ' )
58
58
}
59
- mut unwrapped := g.unwrap_generic (typ).set_nr_muls (0 ).clear_flag (.variadic)
59
+ mut unwrapped := if typ.has_flag (.option) {
60
+ g.unwrap_generic (typ).clear_flag (.variadic)
61
+ } else {
62
+ g.unwrap_generic (typ).set_nr_muls (0 ).clear_flag (.variadic)
63
+ }
60
64
if g.pref.nofloat {
61
65
if typ == ast.f32_ type {
62
66
unwrapped = ast.u32_ type
@@ -515,6 +519,9 @@ fn styp_to_str_fn_name(styp string) string {
515
519
516
520
// deref_kind returns deref, deref_label
517
521
fn deref_kind (str_method_expects_ptr bool , is_elem_ptr bool , typ ast.Type) (string , string ) {
522
+ if typ.has_flag (.option) {
523
+ return '' , ''
524
+ }
518
525
if str_method_expects_ptr != is_elem_ptr {
519
526
if is_elem_ptr {
520
527
return '*' .repeat (typ.nr_muls ()), '&' .repeat (typ.nr_muls ())
@@ -936,7 +943,11 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, typ_str string,
936
943
caller_should_free = false
937
944
} else if ftyp_noshared.is_ptr () {
938
945
// reference types can be "nil"
939
- funcprefix + = 'isnil(it.${c_name(field.name)} )'
946
+ if ftyp_noshared.has_flag (.option) {
947
+ funcprefix + = 'isnil(&it.${c_name(field.name)} )'
948
+ } else {
949
+ funcprefix + = 'isnil(it.${c_name(field.name)} )'
950
+ }
940
951
funcprefix + = ' ? _SLIT("nil") : '
941
952
// struct, floats and ints have a special case through the _str function
942
953
if sym.kind ! in [.struct_, .alias, .enum_, .sum_type, .map , .interface_]
0 commit comments