parent
							
								
									874885c87d
								
							
						
					
					
						commit
						a65b73d3e4
					
				|  | @ -1288,21 +1288,15 @@ fn (mut g Gen) for_in(it ast.ForInStmt) { | |||
| 	} else if it.kind == .array_fixed { | ||||
| 		atmp := g.new_tmp_var() | ||||
| 		atmp_type := g.typ(it.cond_type).trim('*') | ||||
| 		if !it.cond.is_lvalue() { | ||||
| 			g.write('$atmp_type *$atmp = ') | ||||
| 			if !it.cond_type.is_ptr() { | ||||
| 				g.write('&') | ||||
| 		if it.cond_type.is_ptr() || it.cond is ast.ArrayInit { | ||||
| 			if !it.cond.is_lvalue() { | ||||
| 				g.write('$atmp_type *$atmp = (($atmp_type)') | ||||
| 			} else { | ||||
| 				g.write('$atmp_type *$atmp = (') | ||||
| 			} | ||||
| 			g.write('(($atmp_type)') | ||||
| 		} else { | ||||
| 			g.write('$atmp_type *$atmp = ') | ||||
| 			if !it.cond_type.is_ptr() { | ||||
| 				g.write('&') | ||||
| 			} | ||||
| 			g.write('(') | ||||
| 			g.expr(it.cond) | ||||
| 			g.writeln(');') | ||||
| 		} | ||||
| 		g.expr(it.cond) | ||||
| 		g.writeln(');') | ||||
| 		i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var } | ||||
| 		cond_sym := g.table.get_type_symbol(it.cond_type) | ||||
| 		info := cond_sym.info as table.ArrayFixed | ||||
|  | @ -1316,10 +1310,13 @@ fn (mut g Gen) for_in(it ast.ForInStmt) { | |||
| 				styp := g.typ(it.val_type) | ||||
| 				g.write('\t$styp ${c_name(it.val_var)}') | ||||
| 			} | ||||
| 			if it.val_is_mut { | ||||
| 				g.writeln(' = &(*$atmp)[$i];') | ||||
| 			addr := if it.val_is_mut { '&' } else { '' } | ||||
| 			if it.cond_type.is_ptr() || it.cond is ast.ArrayInit { | ||||
| 				g.writeln(' = ${addr}(*$atmp)[$i];') | ||||
| 			} else { | ||||
| 				g.writeln(' = (*$atmp)[$i];') | ||||
| 				g.write(' = $addr') | ||||
| 				g.expr(it.cond) | ||||
| 				g.writeln('[$i];') | ||||
| 			} | ||||
| 		} | ||||
| 	} else if it.kind == .map { | ||||
|  |  | |||
|  | @ -85,3 +85,17 @@ fn test_iteration_over_fixed_array_literal() { | |||
| 	} | ||||
| 	assert s == 27.25 | ||||
| } | ||||
| 
 | ||||
| fn calc_size(a [3]int) { | ||||
| 	mut s := 0 | ||||
| 	for i in a { | ||||
| 		println(i) | ||||
| 		s += i | ||||
| 	} | ||||
| 	assert s == 6 | ||||
| } | ||||
| 
 | ||||
| fn test_for_in_fixed_array() { | ||||
| 	arr := [1,2,3]! | ||||
| 	calc_size(arr) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue