Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2011-12-19 15:21:31 +0400
committerZoltan Varga <vargaz@gmail.com>2011-12-19 15:21:58 +0400
commitcd3c79413ad17ccdf34aaae9347f33b7e5aa1b16 (patch)
tree01903164837eeb4055a447b39f9f0203c2de0e4f
parentbc36fbe19302faf3de2c82c06df98df9aa4f048e (diff)
Fix List.LastIndexOf () on empty lists. Fixes #2558.
-rw-r--r--mcs/class/corlib/System.Collections.Generic/List.cs2
-rw-r--r--mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs6
2 files changed, 8 insertions, 0 deletions
diff --git a/mcs/class/corlib/System.Collections.Generic/List.cs b/mcs/class/corlib/System.Collections.Generic/List.cs
index 7646b777ba7..c666eea72be 100644
--- a/mcs/class/corlib/System.Collections.Generic/List.cs
+++ b/mcs/class/corlib/System.Collections.Generic/List.cs
@@ -467,6 +467,8 @@ namespace System.Collections.Generic {
public int LastIndexOf (T item)
{
+ if (_size == 0)
+ return -1;
return Array.LastIndexOf<T> (_items, item, _size - 1, _size);
}
diff --git a/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs b/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs
index 366f270bf79..d33699ecdb8 100644
--- a/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs
+++ b/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs
@@ -1307,6 +1307,12 @@ namespace MonoTests.System.Collections.Generic {
Assert.IsTrue (e is ArgumentException, "#10");
}
}
+
+ [Test]
+ public void LastIndexOfEmpty_2558 () {
+ var l = new List<int> ();
+ Assert.AreEqual (-1, l.IndexOf (-1));
+ }
}
}
#endif