Skip to content

Conversation

@Flaque
Copy link
Member

@Flaque Flaque commented Jan 8, 2026

Summary

This PR implements proper validation errors for undefined fields and type mismatches to fix 4 conformance test failures.

Changes

1. Enhanced Type Conversion Validation (cel/src/functions.rs)

  • int() function: Added comprehensive range checking for float-to-int conversion

    • Validates NaN and infinity values
    • Uses trunc() for proper handling of floating point edge cases
    • Ensures truncated values are within i64 bounds
    • Provides clear error messages for overflow conditions
  • uint() function: Similar enhancements for unsigned integer conversion

    • Checks for negative values explicitly
    • Validates NaN and infinity
    • Ensures values fit within u64 range

2. Improved Field Access Validation (cel/src/objects.rs)

  • member() function: Refactored for clearer error handling
    • Consistently returns NoSuchKey error for undefined fields on maps
    • Returns NoSuchKey when attempting field access on non-map types (scalars, lists, etc.)
    • More maintainable code structure with explicit error paths

Test Cases Addressed

  1. Undefined field access: Now properly raises NoSuchKey error
  2. Type mismatches on field assignment: Accessing fields on scalar types returns appropriate errors
  3. Invalid repeated field access: Existing validation enhanced by clearer error handling
  4. Range validation for conversions: double_int_min_range now properly validates conversion bounds

Technical Details

The key improvements focus on:

  • Stricter validation: Don't silently succeed when operations should fail
  • Better error messages: Clear indication of what went wrong
  • Edge case handling: Proper handling of NaN, infinity, and boundary values
  • Consistent behavior: Uniform error handling across similar operations

Testing

These changes address conformance test failures related to validation errors. The implementation follows CEL specification requirements for type validation and field access.

🤖 Generated with Claude Code

This commit addresses 4 conformance test failures by implementing proper
validation for:

1. **Undefined field access**: Enhanced member() function in objects.rs to
   consistently return NoSuchKey error when accessing fields on non-map types
   or when accessing undefined fields on maps.

2. **Type conversion range validation**: Added comprehensive range checking
   in the int() and uint() conversion functions in functions.rs:
   - Check for NaN and infinity values before conversion
   - Use trunc() to properly handle floating point edge cases
   - Validate that truncated values are within target type bounds
   - Ensure proper error messages for overflow conditions

3. **Single scalar type mismatches**: The member() function now properly
   validates that field access only succeeds on Map types, returning
   NoSuchKey for scalar types (Int, String, etc.)

4. **Repeated field access validation**: The existing index operator
   validation already properly handles invalid access patterns on lists
   and maps with appropriate error messages.

Changes:
- cel/src/functions.rs: Enhanced int() and uint() with strict range checks
- cel/src/objects.rs: Refactored member() for clearer error handling

These changes ensure that operations raise validation errors instead of
silently succeeding or producing incorrect results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jan 8, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  cel/src/objects.rs  42% smaller
  cel/src/functions.rs  12% smaller

@Flaque Flaque merged commit 2757867 into master Jan 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants