parent
							
								
									874885c87d
								
							
						
					
					
						commit
						a65b73d3e4
					
				|  | @ -1288,21 +1288,15 @@ fn (mut g Gen) for_in(it ast.ForInStmt) { | ||||||
| 	} else if it.kind == .array_fixed { | 	} else if it.kind == .array_fixed { | ||||||
| 		atmp := g.new_tmp_var() | 		atmp := g.new_tmp_var() | ||||||
| 		atmp_type := g.typ(it.cond_type).trim('*') | 		atmp_type := g.typ(it.cond_type).trim('*') | ||||||
| 		if !it.cond.is_lvalue() { | 		if it.cond_type.is_ptr() || it.cond is ast.ArrayInit { | ||||||
| 			g.write('$atmp_type *$atmp = ') | 			if !it.cond.is_lvalue() { | ||||||
| 			if !it.cond_type.is_ptr() { | 				g.write('$atmp_type *$atmp = (($atmp_type)') | ||||||
| 				g.write('&') | 			} else { | ||||||
|  | 				g.write('$atmp_type *$atmp = (') | ||||||
| 			} | 			} | ||||||
| 			g.write('(($atmp_type)') | 			g.expr(it.cond) | ||||||
| 		} else { | 			g.writeln(');') | ||||||
| 			g.write('$atmp_type *$atmp = ') |  | ||||||
| 			if !it.cond_type.is_ptr() { |  | ||||||
| 				g.write('&') |  | ||||||
| 			} |  | ||||||
| 			g.write('(') |  | ||||||
| 		} | 		} | ||||||
| 		g.expr(it.cond) |  | ||||||
| 		g.writeln(');') |  | ||||||
| 		i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var } | 		i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var } | ||||||
| 		cond_sym := g.table.get_type_symbol(it.cond_type) | 		cond_sym := g.table.get_type_symbol(it.cond_type) | ||||||
| 		info := cond_sym.info as table.ArrayFixed | 		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) | 				styp := g.typ(it.val_type) | ||||||
| 				g.write('\t$styp ${c_name(it.val_var)}') | 				g.write('\t$styp ${c_name(it.val_var)}') | ||||||
| 			} | 			} | ||||||
| 			if it.val_is_mut { | 			addr := if it.val_is_mut { '&' } else { '' } | ||||||
| 				g.writeln(' = &(*$atmp)[$i];') | 			if it.cond_type.is_ptr() || it.cond is ast.ArrayInit { | ||||||
|  | 				g.writeln(' = ${addr}(*$atmp)[$i];') | ||||||
| 			} else { | 			} else { | ||||||
| 				g.writeln(' = (*$atmp)[$i];') | 				g.write(' = $addr') | ||||||
|  | 				g.expr(it.cond) | ||||||
|  | 				g.writeln('[$i];') | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} else if it.kind == .map { | 	} else if it.kind == .map { | ||||||
|  |  | ||||||
|  | @ -85,3 +85,17 @@ fn test_iteration_over_fixed_array_literal() { | ||||||
| 	} | 	} | ||||||
| 	assert s == 27.25 | 	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