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

Method overload #84

Open
NetDefender opened this issue Nov 16, 2020 · 1 comment
Open

Method overload #84

NetDefender opened this issue Nov 16, 2020 · 1 comment

Comments

@NetDefender
Copy link

NetDefender commented Nov 16, 2020

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
Copy link
Contributor

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?

hunkydoryrepair added a commit to hunkydoryrepair/Flee that referenced this issue Mar 26, 2021
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

No branches or pull requests

2 participants