File tree Expand file tree Collapse file tree 4 files changed +10
-2
lines changed
Expand file tree Collapse file tree 4 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ pub mut:
4747 is_index_expr bool
4848 is_mbranch_expr bool // match a { x...y { } }
4949 is_struct_init bool
50+ is_array_init bool
5051 fn_scope & ast.Scope = unsafe { nil }
5152 wsinfix_depth int
5253 format_state FormatState
@@ -1839,7 +1840,10 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
18391840 }
18401841 if node.has_init {
18411842 f.write ('init: ' )
1843+ old_is_array_init := f.is_array_init
1844+ f.is_array_init = true
18421845 f.expr (node.init_expr)
1846+ f.is_array_init = old_is_array_init
18431847 }
18441848 f.write ('}' )
18451849 return
@@ -2358,6 +2362,8 @@ pub fn (mut f Fmt) ident(node ast.Ident) {
23582362 name := f.short_module (node.name)
23592363 if node.name.contains ('__static__' ) {
23602364 f.write_static_method (node.name, name)
2365+ } else if f.is_array_init && name == 'it' {
2366+ f.write ('index' )
23612367 } else {
23622368 f.write (name)
23632369 }
Original file line number Diff line number Diff line change 1+ println([]int{len: 10, init: index + 2})
Original file line number Diff line number Diff line change 1+ println([]int{len: 10, init: it + 2})
Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ fn main() {
2222
2323 // index initializations
2424 list1 := []string {len: 3 , init: 'Item ${index} ' }
25- list2 := []string {len: 3 , init: 'Item ${it } ' }
25+ list2 := []string {len: 3 , init: 'Item ${index } ' }
2626 list3 := []int {len: 3 , init: index}
27- list4 := []string {len: 4 , init: '${index} :${it * 2} ' }
27+ list4 := []string {len: 4 , init: '${index} :${index * 2} ' }
2828 println (list1 )
2929 println (list2 )
3030 println (list1 == list2 )
You can’t perform that action at this time.
0 commit comments