Skip to content

TUnit0001 rejects an int method source for a nullable generic class parameter #7573

Closed
2 of 2 issues completed

Description

@thomhurst

Summary

The TUnit0001 analyzer rejects a typed method data source returning IEnumerable<int> when its test parameter is T? on a generic class constrained with where T : struct. Reflection discovery infers T = int and executes the row successfully; source-generated discovery also supports this after PR #7571. The diagnostic prevents users from building the supported test.

Reproduction

public class Tests<T> where T : struct
{
    public static IEnumerable<int> Rows() => [1];
    [Test, MethodDataSource(nameof(Rows))]
    public void Run(T? value) { }
}

Build with the TUnit analyzer. Actual: TUnit0001 reports that int does not match T?. Expected: infer the underlying int and accept the test.

Environment

.NET SDK 10.0.403, repository head 4fd4387. Reproduced while validating PR #7571 in tests/TUnit.TestProject/Bugs/_7224/MethodSourceClassInferenceTests.cs, NullableValue. The analyzer also remains unchanged on main at 98b0697. The runtime regression temporarily suppresses this diagnostic.

Please make nullable generic class method-parameter validation agree with discovery and add analyzer coverage.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 4, 2026
  2. 5 remaining items

  3. added and removed on Nov 4, 2026
  4. thomhurst commented on Nov 5, 2026

    @thomhurst
    OwnerAuthor

    Rechecked the parent against origin/main at 55f4100. Both native sub-issues are closed: #7610 shipped via #7613 (3dfd584), and #7611 shipped via #7614 (55f4100). The analyzer accepts int/int? rows for T? and retains constraint regressions; discovery retains generated/reflection parity and constructor precedence. The merged PRs contain full analyzer/generator and Native AOT validation and passing CI.

    The remaining cleanup was a fixture-wide TUnit0001 suppression and comment saying the analyzer fix was pending. #7626 removes both and closes this parent when merged. With the suppression removed, a fresh net10.0 build succeeded and all 39 targeted _7573 cases passed in generated mode and all 39 passed in reflection mode (SDK 10.0.403, macOS arm64). No engine integration suite was run locally, per repository guidance. Existing build warning debt is tracked in #7410, #7412 and #7430.

  5. thomhurst commented on Nov 5, 2026

    @thomhurst
    OwnerAuthor

    Additional nullable analyzer reproduction found while validating #7630: C<TClass> closed with [GenerateGenericTest(typeof(int))] (or [Arguments<int>(1)]) has static IEnumerable<TClass> StaticRows() => [default!]; and [Test, GenerateGenericTest(typeof(int)), MethodDataSource(nameof(StaticRows))] void BothSources<T>(T? item) where T : struct { }. Building reports TUnit0001 that TClass does not match T?, despite the closed class/method pair being int/int and execution succeeding in both discovery modes. Expected: accept that compatible closed pairing. SDK 10.0.403; reproduction is in tests/TUnit.TestProject/Bugs/_7222/GenericInstanceSourceTests.cs on #7630, with an explanatory suppression so its discovery regressions compile. Please include this method-generic/closed-class variant in the remaining nullable analyzer work.

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 workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions