Skip to content

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

Done
1 of 2 issues completed
Done

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.

Sub-issues

Sub-issues

1 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    bug
    P2
    on Nov 3, 2026
  2. added
    in-progress
    on Nov 3, 2026
  3. removed
    in-progress
    on Nov 4, 2026
  4. thomhurst commented on Nov 29, 2026

    @thomhurst
    OwnerAuthor

    This no longer reproduces on main. The exact repro from this issue passes TUnit0001 on main, most likely since #7541 ("Fix generic array binding inside tuple data-source parameters"). #7883 adds it as a regression test, SharedRowBindingTests.Generic_Array_Element_Inside_A_Tuple_Parameter.

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

    P2bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions