Validate function calls using TypeSpec and TypeValidator
(
func_call: &FunctionCall,
ctx: &mut ValidationContext,
errors: &mut Vec<ValidationError>,
)
| 1533 | |
| 1534 | /// Validate function calls using TypeSpec and TypeValidator |
| 1535 | fn validate_function_call( |
| 1536 | func_call: &FunctionCall, |
| 1537 | ctx: &mut ValidationContext, |
| 1538 | errors: &mut Vec<ValidationError>, |
| 1539 | ) { |
| 1540 | // Case-insensitive function lookup |
| 1541 | let func_name_upper = func_call.name.to_uppercase(); |
| 1542 | |
| 1543 | // Check if function exists and clone the signature to avoid borrow checker issues |
| 1544 | let signature = match ctx.function_signatures.get(&func_name_upper).cloned() { |
| 1545 | Some(sig) => sig, |
| 1546 | None => { |
| 1547 | errors.push(ValidationError { |
| 1548 | message: format!("Unknown function '{}'", func_call.name), |
| 1549 | location: None, |
| 1550 | error_type: ValidationErrorType::Semantic, |
| 1551 | }); |
| 1552 | return; |
| 1553 | } |
| 1554 | }; |
| 1555 | |
| 1556 | // Validate each argument expression |
| 1557 | for arg in &func_call.arguments { |
| 1558 | validate_expression(arg, ctx, errors); |
| 1559 | } |
| 1560 | |
| 1561 | // For variadic functions (like COUNT), allow flexible argument counts |
| 1562 | if signature.variadic { |
| 1563 | if func_name_upper == "COUNT" { |
| 1564 | // COUNT can have 0 (COUNT(*)) or 1 argument (COUNT(expr)) |
| 1565 | if func_call.arguments.len() > 1 { |
| 1566 | errors.push(ValidationError { |
| 1567 | message: format!( |
| 1568 | "Function '{}' expects 0 or 1 arguments, got {}", |
| 1569 | func_call.name, |
| 1570 | func_call.arguments.len() |
| 1571 | ), |
| 1572 | location: None, |
| 1573 | error_type: ValidationErrorType::Type, |
| 1574 | }); |
| 1575 | return; |
| 1576 | } |
| 1577 | } |
| 1578 | // For other variadic functions, just ensure minimum arguments |
| 1579 | if func_call.arguments.len() < signature.argument_types.len() { |
| 1580 | errors.push(ValidationError { |
| 1581 | message: format!( |
| 1582 | "Function '{}' expects at least {} arguments, got {}", |
| 1583 | func_call.name, |
| 1584 | signature.argument_types.len(), |
| 1585 | func_call.arguments.len() |
| 1586 | ), |
| 1587 | location: None, |
| 1588 | error_type: ValidationErrorType::Type, |
| 1589 | }); |
| 1590 | } |
| 1591 | return; |
| 1592 | } |
no test coverage detected