mparlak / Flee

Fast Lightweight Expression Evaluator
607 stars 119 forks source link

Method overload #84

Open NetDefender opened 3 years ago

NetDefender commented 3 years ago

Hi, This is a wonderful library. I have problem with method overloads and i have seen how to correct it. In the image below, the result of the division on ComputeScoreInternal should be a float, if not there are duplicates in score. ComputeSum is working fine but the division after is coercing the value to int, so If i call the function MyFunc(1,1):

void MyFunc(int a, int b); => 0 Score void MyFunc(decimal a, decimal b => 0 Score Wrong

They are returning the same score.

Wrong: Before

Right: After

hunkydoryrepair commented 3 years ago

This seems unlikely, although I think your change is a good one. In your example, the "score" for converting an Int to a Decimal is 5. Converting two Int32 to Decimal would give a SUM of 10, and then divided by 2 is 5. The score on the second one would be 5, not 0. For this to be an issue, there would either need to be a lot more parameters or the conversion would be much closer than int->decimal. An Int32 -> UInt32, for example, only returns 1, and if just one of the arguments was not a match, then you'd hit the integer rounding.

Did you actually have a test case where the wrong method was getting called?