nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #02914
[Bug 1051847] Re: self contained item in array causes stack overflow
The problem with the code above is not really in the comparison between
the two references to item (the variable and the element in the array)
but rather with the non-failing comparison between item and the new
instance of SelfContainer in position 0 in the array, which causes the
stack overflow. That is quite easy to fix, but while working on it and
writing some tests I encountered an interesting scenario:
object[] array1 = new object[2];
array1[0] = 1;
array1[1] = array1;
object[] array2 = new object[2];
array2[0] = 1;
array2[1] = array2;
Should array1 and array2 be considered equal?
The first element is definitely equal, it's 1. What about the second
element of each of them? They are self references to the arrays, which
in turn contain 1 at the first element and another self reference, and
so on forever.
We can implement it either way, but I'm not sure what is the "correct"
one.
--
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1051847
Title:
self contained item in array causes stack overflow
Status in NUnit V2 Test Framework:
Confirmed
Bug description:
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class Reproduction {
class SelfContainer : IEnumerable { public IEnumerator GetEnumerator() { yield return this; } }
[Test]
public void SelfContainedItemFoundInArray() {
var item = new SelfContainer();
var items = new SelfContainer[] { new SelfContainer(), item };
// work around
Assert.True(((ICollection<SelfContainer>)items).Contains(item));
// causes StackOverflowException
Assert.Contains(item, items);
}
}
Reproduced in NUnit 2.6.1
See also bug #491300
To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/1051847/+subscriptions
References