Function check_mixed_arithmetic_operation

Source
pub fn check_mixed_arithmetic_operation(
    context: &CompilationContext,
    left_type: &TypeId,
    right_type: &TypeId,
    bin_expr: &BinaryExpr,
) -> SemanticResult
Expand description

Checks if mixed-type arithmetic operations are allowed, particularly handling unspecified literals that can be coerced to match the other operand’s type. This function handles type coercion for arithmetic operations when operands have different types.

§Supported Cases

  • Unspecified integer literal + specific integer type
  • Unspecified float literal + specific float type
  • String concatenation with the + operator

§Arguments

  • context - The compilation context
  • left_type - The type of the left operand
  • right_type - The type of the right operand
  • bin_expr - The binary expression containing both operands and the operator

§Returns

  • Ok(type_id) with the resulting operation type if allowed
  • Err with a descriptive error message if the operation is not allowed