Skip to content

The type of an Array isn't inferred from properly #3259

Description

Using arrays of any dimension does not work in this example and ends up in the TestFixture failing to Set-up: (System.IndexOutOfRangeException trace)

static object[] populateTestCases = new object[]
        {
            new object[] { new int[40], 10}
        };

        [Test, TestCaseSource(nameof(populateTestCases))]
        public void PopulateTest<T>(T[] array, T value)
        {
            foreach (var item in array)
                Assert.AreEqual(item, value);
        }

However using a List<T> works fine: (The test compiles and behaves properly)

static object[] populateTestCases = new object[]
        {
            new object[] { new List<int>(40), 10}
        };

        [Test, TestCaseSource(nameof(populateTestCases))]
        public void PopulateTest<T>(List<T> array, T value)
        {
            foreach (var item in array)
                Assert.AreEqual(item, value);
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions