implicit address-taking for array slices

This commit is contained in:
2026-06-23 18:44:59 +02:00
parent 18e2a96b76
commit c7e171c438
5 changed files with 102 additions and 6 deletions
+20 -3
View File
@@ -244,9 +244,26 @@ lower_compound_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instructi
diagnostic=source.INVALID_DIAGNOSTIC,
})
case .Slice:
container := lower_nested_expr(state, expr.left)
if types.is_array(state.hir_module.exprs[expr.left].type, &state.hir_module.types) {
container = lower_location(state, expr.left)
left_type := state.hir_module.exprs[expr.left].type
container: ir.Instruction_Id
if types.is_array(left_type, &state.hir_module.types) {
if hir_expr_is_location(state, expr.left) {
container = lower_location(state, expr.left)
} else {
value := lower_nested_expr(state, expr.left)
container = append_instruction(state, ir.Instruction{
op=.Alloca, span=expr.span, type=left_type,
target=ir.INVALID_REF, a=ir.INVALID_INSTRUCTION, b=ir.INVALID_INSTRUCTION,
diagnostic=source.INVALID_DIAGNOSTIC,
})
append_instruction(state, ir.Instruction{
op=.Store, span=expr.span, type=left_type,
target=ir.INVALID_REF, a=container, b=value,
diagnostic=source.INVALID_DIAGNOSTIC,
})
}
} else {
container = lower_nested_expr(state, expr.left)
}
args := make([]ir.Instruction_Id, len(expr.args), state.allocator)
for arg, index in expr.args {