Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Incorrect Handling of Qualifiers in ConstantExpressionHelper #824

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

RenanCarlosPereira
Copy link
Contributor

Description:
There is an issue in the ExpressionPromoter class where the qualifier in the numeric literal expressions is not correctly handled, leading to incorrect type promotions. This is due to the way qualifiers are stored and retrieved from the ConstantExpressionHelper.

Steps to Reproduce:

  1. Create an instance of ParsingConfig.
  2. Use NumberParser to parse a numeric literal with a qualifier.
  3. Attempt to promote the parsed expression to a different type using ExpressionPromoter.

Example 1:

[Fact]
public void promoter()
{
    // Assign
    var parsingConfig = new ParsingConfig();
    var numberParser = new NumberParser(parsingConfig);
    var promoter = new ExpressionPromoter(parsingConfig);

    var doubleExpression = numberParser.ParseRealLiteral("10.5d", 'd', true);

    // Act & Assert
    var promotedExpression = promoter.Promote(doubleExpression, typeof(decimal), true, true);

    Assert.NotNull(promotedExpression);
    Assert.Equal(typeof(decimal), promotedExpression.Type);
}

Example 2:

[Fact]
public void promoteDoubleToDecimal()
{
    // Assign
    var parsingConfig = new ParsingConfig();
    var numberParser = new NumberParser(parsingConfig);
    var promoter = new ExpressionPromoter(parsingConfig);

    var doubleExpression = numberParser.ParseRealLiteral("123.456d", 'd', true);

    // Act & Assert
    var promotedExpression = promoter.Promote(doubleExpression, typeof(decimal), true, true);

    Assert.NotNull(promotedExpression);
    Assert.Equal(typeof(decimal), promotedExpression.Type);
}

Expected Behavior:
The Promote method should correctly handle the qualifier and convert the numeric literal to the specified target type.

Actual Behavior:
The promotion fails, and the conversion does not occur as expected due to the incorrect handling of the qualifier in the ConstantExpressionHelper.

Additional Information:
This issue affects applications that rely on dynamic LINQ queries where numeric-type promotions with qualifiers are necessary.

Proposed Solution:
Ensure that the CreateLiteral in ConstantExpressionHelper correctly handles qualifiers without the prefix when creating and retrieving constant expressions.

@RenanCarlosPereira
Copy link
Contributor Author

@StefH could you review it, then if possible we could update the rules engine 😅

@StefH
Copy link
Collaborator

StefH commented Jun 25, 2024

@RenanCarlosPereira
Can you merge the latest master into your branch? I want to check if the GitHub action also gets triggered for this PR.

@StefH could you review it, then if possible we could update the rules engine 😅

  • I will.
  • Which project is that ?

@RenanCarlosPereira
Copy link
Contributor Author

RenanCarlosPereira commented Jun 25, 2024

the bug related is in the rules engine, I actually need to open a bug over there and reference it here:
because the bug itself its not in the rules engine, but this PR will solve the issue and we will have to upgrade the package:
microsoft/RulesEngine#604 (comment)
#821

I am unsure why GitHub actions are not triggering, merge is done!

@StefH StefH changed the title Incorrect Handling of Qualifiers in ConstantExpressionHelper Fixed: Incorrect Handling of Qualifiers in ConstantExpressionHelper Jun 25, 2024
@StefH StefH merged commit d14b76e into zzzprojects:master Jun 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants