Skip to content
This repository has been archived by the owner on Aug 22, 2018. It is now read-only.

[Core] LastIndexOf{T} method in EnumerableExtensions.cs has invalid implementation for IList{T} branch. #62

Closed
discosultan opened this issue Oct 26, 2014 · 6 comments
Assignees
Milestone

Comments

@discosultan
Copy link

Hello!

I'll just post the failing code snippet. Should be self explanatory ;)

        var range1 = new Stack<int>(); range1.Push(1); // This will hit the IEnumerable branch of LastIndexOf method.
        var range2 = new[] { 1 }; // This will hit the IList branch of LastIndexOf method.

        Console.WriteLine(range1.IndexOf(x => x == 1)); // 0
        Console.WriteLine(range2.IndexOf(x => x == 1)); // 0
        Console.WriteLine(range1.LastIndexOf(x => x == 1)); // 0
        Console.WriteLine(range2.LastIndexOf(x => x == 1)); // -1 Incorrect!
@gitfool
Copy link

gitfool commented Oct 26, 2014

You can link to the source now; EnumerableExtensions.cs:86 should use i >= 0.

@discosultan
Copy link
Author

Thanks for the tip about source code linkage.

@gitfool
Copy link

gitfool commented Oct 27, 2014

You're welcome. That's a nice obvious fix, so the next step would've been to fork the repo and submit a pull request. ;)

@discosultan
Copy link
Author

This seemed like a small enough fix that I couldn't bother with a pull request.

I didn't notice at first, but actually the implementation for the IEnumerable branch is also broken and will return the first index instead of the last one.

EnumerableExtensions.cs#L93-L100

@Benlitz
Copy link

Benlitz commented Oct 28, 2014

Looks like you're right :) This method will be fixed in the next release, sorry for that

@xen2 xen2 added this to the beta03 milestone Oct 28, 2014
@discosultan
Copy link
Author

Np! I'm glad if I can be of any help.

@xen2 xen2 added the fixed label Nov 4, 2014
@xen2 xen2 assigned xen2 and unassigned Benlitz Nov 4, 2014
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants