feat: support boolean conditional expressions
This commit is contained in:
@@ -1615,6 +1615,14 @@ demand proc(state @mut State, id ast.NodeId, expected Type, code diagnostics.Cod
|
||||
return
|
||||
}
|
||||
}
|
||||
if (state.cells[usize(id)].role == .expression and ast.expr_kind(state.tree, id) == .match_expr) {
|
||||
state.cells[index].expected = expected
|
||||
for 0..ast.match_arm_count(state.tree, id) |i| {
|
||||
arm :: ast.match_arm_view(state.tree, ast.match_arm(state.tree, id, i))
|
||||
if (arm.expression) try demand(state, arm.body, expected, code)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (expected.kind == .fallible) {
|
||||
descriptor :: state.arrays.items[usize(expected.array_type)]
|
||||
actual := group_type(state, id)
|
||||
@@ -1691,14 +1699,6 @@ demand proc(state @mut State, id ast.NodeId, expected Type, code diagnostics.Cod
|
||||
state.pointers.items[usize(expected.pointer_type)].element, code)
|
||||
return
|
||||
}
|
||||
if (state.cells[usize(id)].role == .expression and ast.expr_kind(state.tree, id) == .match_expr) {
|
||||
state.cells[index].expected = expected
|
||||
for 0..ast.match_arm_count(state.tree, id) |i| {
|
||||
arm :: ast.match_arm_view(state.tree, ast.match_arm(state.tree, id, i))
|
||||
if (arm.expression) try demand(state, arm.body, expected, code)
|
||||
}
|
||||
return
|
||||
}
|
||||
literal_node :: state.cells[index].literal
|
||||
if (
|
||||
expected.nominal != ast.NodeId(maxval!(u32))
|
||||
|
||||
@@ -4349,6 +4349,18 @@ expression_type proc(state @mut State, id ast.NodeId, depth usize) ast.NodeId !
|
||||
.literal_bool: return try builtin(state, id, .bool)
|
||||
.literal_string: return try builtin(state, id, .string)
|
||||
.literal_void: return try builtin(state, id, .void)
|
||||
.match_expr: {
|
||||
result := no_node
|
||||
for (0..ast.match_arm_count(&state.tree, id)) |i| {
|
||||
arm :: ast.match_arm_view(&state.tree, ast.match_arm(&state.tree, id, i))
|
||||
if (!arm.expression) return no_node
|
||||
annotation :: try expression_type(state, arm.body, depth + 1)
|
||||
if (annotation == no_node) continue
|
||||
result = annotation
|
||||
if (!flexible(state, arm.body)) return result
|
||||
}
|
||||
return result
|
||||
}
|
||||
.builtin_call: {
|
||||
name :: ast.literal_text(&state.tree, ast.builtin_call(&state.tree, id).name)
|
||||
count :: ast.call_arg_count(&state.tree, id)
|
||||
|
||||
Reference in New Issue
Block a user