fmt: fix optional formatting

pull/4553/head
Kris Cherven 2020-04-22 14:12:58 -04:00 committed by GitHub
parent fecf4ddf65
commit faed178cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -452,9 +452,9 @@ fn (f &Fmt) type_to_str(t table.Type) string {
mut res := f.table.type_to_str(t) mut res := f.table.type_to_str(t)
// type_ptr => &type // type_ptr => &type
if res.ends_with('_ptr') { if res.ends_with('_ptr') {
res = res[0..res.len - 4] res = res[0 .. res.len - 4]
start_pos := 2 * res.count('[]') start_pos := 2 * res.count('[]')
res = res[0..start_pos] + '&' + res[start_pos..res.len] res = res[0 .. start_pos] + '&' + res[start_pos .. res.len]
} }
return res.replace(f.cur_mod + '.', '') return res.replace(f.cur_mod + '.', '')
} }

View File

@ -0,0 +1,5 @@
pub fn test() ?&SomeType {
}
struct SomeType {
}

View File

@ -631,13 +631,13 @@ pub fn (table &Table) type_to_str(t Type) string {
res = '[]' + res res = '[]' + res
} }
} }
if type_is(t, .optional) {
res = '?' + res
}
nr_muls := type_nr_muls(t) nr_muls := type_nr_muls(t)
if nr_muls > 0 { if nr_muls > 0 {
res = strings.repeat(`&`, nr_muls) + res res = strings.repeat(`&`, nr_muls) + res
} }
if type_is(t, .optional) {
res = '?' + res
}
/* /*
if res.starts_with(cur_mod +'.') { if res.starts_with(cur_mod +'.') {
res = res[cur_mod.len+1.. ] res = res[cur_mod.len+1.. ]