Skip to content

TUnit0001 rejects numeric widening for a single reference-tuple parameter #7480

Closed

Description

@thomhurst

Summary

A method data source returning an eight-element reference tuple of integers is rejected with TUnit0001 when the test accepts the corresponding tuple of longs. The analyzer prevents the test from compiling. Related runtime tuple-conversion support and coverage are in open PR #7469; this issue tracks the analyzer change separately.

Reproduction

public static Tuple<int, int, int, int, int, int, int, Tuple<int>> Row()
    => Tuple.Create(1, 2, 3, 4, 5, 6, 7, 8);

[Test]
[MethodDataSource(nameof(Row))]
public void Test(Tuple<long, long, long, long, long, long, long, Tuple<long>> value) { }

Expected and actual

Expected: accept per-element implicit numeric conversions, as for value tuples.
Actual: TUnit0001 reports that the source and parameter types do not match.

Environment

Found on e452541 with SDK 10.0.403, net10.0, macOS arm64. Reproduced while adding runtime coverage in #7469. The reference-tuple spreading fix in #7457 (for #7374) is already on main; it does not cover this single tuple parameter conversion.

Please validate compatible element conversions for a single reference-tuple parameter, including nested Rest.

Acceptance criteria

  • Accept a single reference-tuple parameter when each source element has a compatible implicit numeric conversion to the corresponding target element, including recursively nested Rest for tuples longer than seven elements.
  • Add analyzer regressions for short reference tuples and the eight-element reproduction above.
  • Keep reporting TUnit0001 for incompatible element types and mismatched tuple lengths; add negative regressions.
  • Preserve existing exact-type single-tuple binding and reference-tuple spreading across multiple parameters.

Current code evidence

At main commit 1f705642be3eec0a1a55034d6210f1532ec5946c, src/TUnit.Analyzers/TestDataAnalyzer.cs preserves a tuple as one argument only when its type exactly equals the single parameter type; otherwise it spreads its elements. ReferenceTupleMethodDataSourceTests covers exact-type whole tuples and spreading, but not whole-tuple numeric widening. Merged PR #7457 addresses spreading; open PR #7469 explicitly leaves this analyzer limitation to #7480.

Activity

  1. added
    bugSomething isn't working
    P3Low: cleanup, minor enhancement, or rare edge case
    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

    P3Low: cleanup, minor enhancement, or rare edge casebugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions