vfmt: fix formatting for [4][4]int static arrays

pull/6490/head
Delyan Angelov 2020-09-27 22:46:33 +03:00
parent cbd7c7d8c6
commit f9ce7f3542
2 changed files with 33 additions and 7 deletions

View File

@ -734,14 +734,26 @@ pub fn (f &Fmt) type_to_str(t table.Type) string {
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]
} }
if res.starts_with('[]fixed_') { arr_fixed_prefix := '[]fixed_'
prefix := '[]fixed_' if res.starts_with(arr_fixed_prefix) {
res = res[prefix.len..] // res: `[]fixed_[]fixed_int_5_10`
last_underscore_idx := res.last_index('_') or { // transforms to: `[10][5]int`
return '[]' + if should_shorten { res.replace_once(cur_mod, '') } else { res } mut last_underscore_idx := 0
mut dimensions := []string{}
for {
res = res[arr_fixed_prefix.len..]
last_underscore_idx = res.last_index('_') or {
return dimensions.join('') + '[]' +
if should_shorten { res.replace_once(cur_mod, '') } else { res }
}
limit := res[last_underscore_idx + 1..]
dimensions << '[$limit]'
res = res[..last_underscore_idx]
if !res.starts_with(arr_fixed_prefix) {
break
}
} }
limit := res[last_underscore_idx + 1..] res = dimensions.join('') + res[..last_underscore_idx]
res = '[' + limit + ']' + res[..last_underscore_idx]
} }
if should_shorten { if should_shorten {
res = res.replace_once(cur_mod, '') res = res.replace_once(cur_mod, '')

View File

@ -0,0 +1,14 @@
struct Board {
mut:
field [10][5]int
points int
shifts int
}
struct TileLine {
ypos int
mut:
field [5]int
points int
shifts int
}