Skip to content

Generic class: [Arguments(null)] method row dropped when class data sources cannot supply the class type argument #7358

Open

Description

@thomhurst

What happens

A generic test class can have class data sources that cannot supply a class type argument, because no public constructor parameter uses a class type parameter. In that case a method-level [Arguments(null)] row is dropped instead of inferring object.

[Arguments(42)]
[MethodDataSource(typeof(Sources), nameof(Sources.FortyThree))] // untyped class source
public class C<T>(int number)
{
    [Test]
    [Arguments(null)]
    public async Task Run(T value) { }
}

From reading the source generator: TestMetadataGenerator.GetConcreteInstantiations computes classTypeArgumentsSupplied (the null-row rule from #7141). #7337 (#7209) excludes class [Arguments] rows whose values go to no type parameter, but every other class data source still counts as supplying the class type arguments. So [Arguments(null)] infers no type, and since no class row instantiates C<object>, the row produces no test.

Reported by CodeRabbit on #7337: #7337 (comment)

Expected

When no public constructor parameter contains a class type parameter, class data sources cannot supply the class type arguments. Method rows should then infer them as without a class data source: C<object> for [Arguments(null)], built from the class sources' rows. This should be the same in both modes.

Notes

Acceptance criteria

  • Reproduce the example on current main in both modes before changing inference.
  • Non-Arguments class sources cannot infer class type arguments from constructor parameters that contain no class type parameter.
  • The null method row runs on C<object> with each class source row supplying its constructor value, with identical counts and values in both modes.

Activity

  1. added
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 1, 2026
  2. thomhurst commented on Nov 2, 2026

    @thomhurst
    OwnerAuthor

    Triage: added a native blocked_by #7209. PR #7337 for #7209 changes classTypeArgumentsSupplied in TestMetadataGenerator.GetConcreteInstantiations, the rule this issue extends. Fixing this first would conflict with that PR.

  3. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Removed the closed #7209 dependency: the core rule merged in #7392 (ca4437c). classTypeArgumentsSupplied still excludes only type-free [Arguments] rows, not other sources whose constructor parameters cannot infer T. #7390 covers parity beside a type-free [Arguments] row; this issue additionally needs non-Arguments class sources to be recognized as type-free. Runtime reproduction remains required.

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