MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / validate_cast_expression

Function validate_cast_expression

graphlite/src/ast/validator.rs:1343–1383  ·  view source on GitHub ↗

Validate CAST expressions

(
    cast_expr: &crate::ast::CastExpression,
    ctx: &mut ValidationContext,
    errors: &mut Vec<ValidationError>,
)

Source from the content-addressed store, hash-verified

1341
1342/// Validate CAST expressions
1343fn validate_cast_expression(
1344 cast_expr: &crate::ast::CastExpression,
1345 ctx: &mut ValidationContext,
1346 errors: &mut Vec<ValidationError>,
1347) {
1348 // Validate the inner expression
1349 validate_expression(&cast_expr.expression, ctx, errors);
1350
1351 // Check if the cast is valid (basic validation - runtime will handle detailed conversion)
1352 if let Ok(_source_type) = infer_expression_type(&cast_expr.expression, ctx) {
1353 // Check for obviously invalid casts
1354 {}
1355 }
1356
1357 // Validate that the target type is well-formed
1358 match &cast_expr.target_type {
1359 GqlType::String {
1360 max_length: Some(len),
1361 } => {
1362 if *len == 0 {
1363 errors.push(ValidationError {
1364 message: "String type cannot have max_length of 0".to_string(),
1365 location: Some(crate::ast::Location::default()),
1366 error_type: ValidationErrorType::Type,
1367 });
1368 }
1369 }
1370 GqlType::Decimal { precision, scale } => {
1371 if let (Some(p), Some(s)) = (precision, scale) {
1372 if *s > *p {
1373 errors.push(ValidationError {
1374 message: "DECIMAL scale cannot be greater than precision".to_string(),
1375 location: Some(crate::ast::Location::default()),
1376 error_type: ValidationErrorType::Type,
1377 });
1378 }
1379 }
1380 }
1381 _ => {} // Other types are valid
1382 }
1383}
1384
1385/// Infer the type of an expression for validation
1386fn infer_expression_type(

Callers 1

validate_expressionFunction · 0.85

Calls 2

validate_expressionFunction · 0.85
infer_expression_typeFunction · 0.85

Tested by

no test coverage detected