Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the handling of arithmetic operations between Enum types and integers in the dynamic LINQ parser. Previously, enums were treated as Int64 for type compatibility checks, which caused incorrect behavior when adding enums and integers.
Key Changes:
- Changed enum type compatibility from TypeCode.Int64 to TypeCode.Int32 to match C#'s actual enum underlying type behavior
- Updated decimal conversion logic to properly handle nullable enum types
- Added comprehensive test coverage for enum arithmetic operations
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/System.Linq.Dynamic.Core/Parser/TypeHelper.cs | Updated IsCompatibleWith to use Int32 for enums instead of Int64, renamed variables for clarity, and added TypesAreEqual helper method |
| src/System.Linq.Dynamic.Core/Parser/ExpressionPromoter.cs | Fixed decimal conversion check to handle nullable types correctly using new TypesAreEqual method |
| test/System.Linq.Dynamic.Core.Tests/Parser/TypeHelperTests.cs | Added comprehensive test coverage for enum type compatibility and renamed existing tests for clarity |
| test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs | Added integration tests for enum+integer and integer+enum addition operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var rangeResult = range.AsQueryable().Select("it + 1"); | ||
|
|
||
| // Assert | ||
| Assert.Equal(range.Select(x => x + 1).ToArray(), rangeResult.Cast<DayOfWeek>().ToArray()); |
There was a problem hiding this comment.
@StefH I believe this is the misleading unit test: rangeResult.Cast<DayOfWeek>() will work, since indeed it is possible to convert the resulting integer to the enum. However, the type inferred from the expression is int rather than DayOfWeek.
No description provided.