yield type check against yield target

This commit is contained in:
2026-08-05 17:35:01 +02:00
parent 84b88f6127
commit aadce94b42
2 changed files with 52 additions and 1 deletions
+18 -1
View File
@@ -12266,7 +12266,9 @@ build_value_block :: proc(
) -> (value: hir.Expr_Id, value_type: types.Type) {
checker := ctx.checker
n := len(body_stmts)
if n == 0 || checker.ast_module.statements[body_stmts[n - 1]].kind != .Yield {
if n == 0 ||
checker.ast_module.statements[body_stmts[n - 1]].kind != .Yield ||
symbol.is_valid(checker.ast_module.statements[body_stmts[n - 1]].label) {
// Build whatever is there so inner errors (and misplaced yields) surface, then
// report the missing trailing yield.
inner := build_block(ctx, body_stmts)
@@ -12657,6 +12659,21 @@ emit_value_branch :: proc(
emit_slot_assign(checker, out, slot^, value, span)
return true
}
if n == 1 {
block_stmt := checker.ast_module.statements[branch_stmts[0]]
if block_stmt.kind == .Block && symbol.is_valid(block_stmt.label) {
expected := slot_type^ if slot^ != hir.INVALID_LOCAL else types.INVALID
value, value_type := build_value_labeled_block(
ctx, out, block_stmt.body, block_stmt.label, expected, block_stmt.span,
)
if checker.module.exprs[value].kind == .Invalid {
return false
}
value = adopt_value_slot(ctx, slot, slot_type, value, value_type, span)
emit_slot_assign(checker, out, slot^, value, span)
return true
}
}
ends_in_yield := n > 0 &&
checker.ast_module.statements[branch_stmts[n - 1]].kind == .Yield &&
!symbol.is_valid(checker.ast_module.statements[branch_stmts[n - 1]].label)