| ... | @@ -1478,9 +1478,26 @@ fn arrayInitExpr( | ... | @@ -1478,9 +1478,26 @@ fn arrayInitExpr( |
| 1478 | | 1478 | |
| 1479 | switch (ri.rl) { | 1479 | switch (ri.rl) { |
| 1480 | .discard => { | 1480 | .discard => { |
| 1481 | // TODO elements should still be coerced if type is provided | 1481 | if (types.elem != .none) { |
| 1482 | for (array_init.ast.elements) |elem_init| { | 1482 | const elem_ri: ResultInfo = .{ .rl = .{ .ty = types.elem } }; |
| 1483 | _ = try expr(gz, scope, .{ .rl = .discard }, elem_init); | 1483 | for (array_init.ast.elements) |elem_init| { |
| | 1484 | _ = try expr(gz, scope, elem_ri, elem_init); |
| | 1485 | } |
| | 1486 | } else if (types.array != .none) { |
| | 1487 | for (array_init.ast.elements, 0..) |elem_init, i| { |
| | 1488 | const elem_ty = try gz.add(.{ |
| | 1489 | .tag = .elem_type_index, |
| | 1490 | .data = .{ .bin = .{ |
| | 1491 | .lhs = types.array, |
| | 1492 | .rhs = @enumFromInt(i), |
| | 1493 | } }, |
| | 1494 | }); |
| | 1495 | _ = try expr(gz, scope, .{ .rl = .{ .ty = elem_ty } }, elem_init); |
| | 1496 | } |
| | 1497 | } else { |
| | 1498 | for (array_init.ast.elements) |elem_init| { |
| | 1499 | _ = try expr(gz, scope, .{ .rl = .discard }, elem_init); |
| | 1500 | } |
| 1484 | } | 1501 | } |
| 1485 | return Zir.Inst.Ref.void_value; | 1502 | return Zir.Inst.Ref.void_value; |
| 1486 | }, | 1503 | }, |
| ... | @@ -1569,7 +1586,7 @@ fn arrayInitExprInner( | ... | @@ -1569,7 +1586,7 @@ fn arrayInitExprInner( |
| 1569 | for (elements, 0..) |elem_init, i| { | 1586 | for (elements, 0..) |elem_init, i| { |
| 1570 | const ri = if (elem_ty != .none) | 1587 | const ri = if (elem_ty != .none) |
| 1571 | ResultInfo{ .rl = .{ .coerced_ty = elem_ty } } | 1588 | ResultInfo{ .rl = .{ .coerced_ty = elem_ty } } |
| 1572 | else if (array_ty_inst != .none and nodeMayNeedMemoryLocation(astgen.tree, elem_init, true)) ri: { | 1589 | else if (array_ty_inst != .none) ri: { |
| 1573 | const ty_expr = try gz.add(.{ | 1590 | const ty_expr = try gz.add(.{ |
| 1574 | .tag = .elem_type_index, | 1591 | .tag = .elem_type_index, |
| 1575 | .data = .{ .bin = .{ | 1592 | .data = .{ .bin = .{ |