Skip to content

TUnit0001 rejects a generic array element inside a tuple parameter #7489

Open
1 of 2 issues completed
Open

Description

@thomhurst

Summary

A method data source returning a tuple with an array element is rejected with TUnit0001 when the test accepts the same tuple with a generic array element. The diagnostic prevents compilation even though the source supplies an int[] and the test can infer T = int.

Reproduction

Add this class to a TUnit test project:

using System.Threading;
using System.Threading.Tasks;
using TUnit.Core;
using TUnit.Core.Interfaces;

public class TupleArrayTests
{
    public static (Fixture, CancellationToken, int[]) Row()
        => (new Fixture(), default, new[] { 1, 2 });

    [Test, MethodDataSource(nameof(Row))]
    public void Test<T>((Fixture, CancellationToken, T[]) row) { }

    public struct Fixture : IAsyncInitializer
    {
        public Task InitializeAsync() => Task.CompletedTask;
    }
}

Build with the analyzers enabled. The compiler reports:

error TUnit0001: Attribute argument types 'Fixture, CancellationToken, int[]' don't match method parameter types '(Fixture, CancellationToken, T[])'

Expected and actual

Expected: infer T = int and accept the compatible tuple element types. Actual: TUnit0001 rejects the row. Replacing the array element with int and the corresponding parameter element with T compiles.

Environment

.NET SDK 10.0.403, net10.0, macOS arm64, PR head 47ce168 plus its review fixes. The review fixes do not change analyzer code. Checked open and closed issues; #7463 concerns expanded trailing arguments, and #7108 concerns non-tuple source discovery. Current main 9100521 retains the generic-array validation path that only checks top-level array parameters, while its newer tuple changes address reference-tuple unwrapping.

Found while validating #7469. Please accept compatible generic array elements inside a single tuple parameter and add positive and negative analyzer regressions.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions