Support other checked operations like + - / * etc.

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Unknown
    • 3.10.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      LINQ queries that perform arithmetic inside a C# checked { } block fail with ExpressionNotSupportedException.

      CSHARP-5606 added support for ExpressionType.ConvertChecked but did not cover the checked arithmetic node kinds the compiler also emits in a checked context: AddChecked, SubtractChecked, MultiplyChecked, and NegateChecked. These are equivalent to their unchecked siblings for translation purposes (MongoDB has no overflow-checked arithmetic operators), so each should translate identically to Add / Subtract / Multiply / Negate.

        var collection = database.GetCollection<C>("c");
        Expression<Func<C, R>> projection;
        checked
        {
            projection = x => new R { V = x.A + x.B };
        }
        var query = collection.AsQueryable().Select(projection);
        var stages = query.ToString(); // or .ToList() 

      Expected: translates to { $project : { V :

      { $add : ['$A', '$B'] }

      , _id : 0 } } — identical to the unchecked form.

      Actual: throws MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression not supported: (x.A + x.B).

      Same failure occurs for , *, unary -, and enum +/ when written inside a checked block, in both Select/$project projections and Where/$match predicates.

            Assignee:
            Damien Guard
            Reporter:
            Damien Guard
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: