slang_frontend/semantic_analysis/operations/logical.rs
1use super::super::traits::SemanticResult;
2use super::helpers;
3use slang_ir::Location;
4use slang_ir::ast::BinaryOperator;
5use slang_types::TypeId;
6
7/// Checks if types are compatible for logical operations (AND, OR).
8/// Both operands must be boolean types.
9///
10/// ### Arguments
11/// * `left_type` - The type of the left operand
12/// * `right_type` - The type of the right operand
13/// * `operator` - The logical operator (either And or Or)
14/// * `location` - The source location of the operation
15///
16/// ### Returns
17/// * `Ok(bool_type())` if both operands are boolean
18/// * `Err` with a descriptive error message otherwise
19pub fn check_logical_operation(
20 left_type: &TypeId,
21 right_type: &TypeId,
22 operator: &BinaryOperator,
23 location: &Location,
24) -> SemanticResult {
25 if helpers::is_boolean_type(left_type) && helpers::is_boolean_type(right_type) {
26 Ok(helpers::bool_type())
27 } else {
28 Err(helpers::logical_operator_type_mismatch_error(
29 &operator.to_string(),
30 left_type,
31 right_type,
32 location,
33 ))
34 }
35}