Skip to content

Generic class with a class [Arguments] row that infers no type argument: modes disagree on T and constructor values, source-gen drops [Arguments(null)] #7209

Open

Description

@thomhurst

What happens

A generic test class has a class-level [Arguments] row whose values go to constructor parameters that are not type parameters. Source-generated mode and reflection mode then choose different instantiations and constructor arguments, and source-generated mode drops an [Arguments(null)] method row.

[Arguments(42)]
public class Probe<T>(int number)
{
    [Test]
    [Arguments(null)]
    [Arguments(1)]
    public async Task Run(T value) =>
        await Assert.That($"T={typeof(T).Name} number={number}").IsEqualTo("show");
}

Observed on the fix/issue-7141-null-row-generic-class branch (PR #7203, based on main at c4b9977), net10.0, filter /*/TUnit.TestProject.Bugs._7141/Probe*/*:

Mode Tests Values
Source-generated 1: Run(1) T=Int32 number=1. The class is built from the method row's value (#7161), and the null row produces no test.
Reflection (--reflection) 2: Run(null), Run(1) T=Int32 number=42 for both. T is inferred from the class row value 42, although the constructor parameter is int, not T.

Expected

Both modes should agree, and no row should vanish. A class row whose values map to no type parameter supplies no class type argument. In that case T should come from the method rows, as it does without a class row: C<int> for [Arguments(1)] and C<object> for [Arguments(null)] (#7141). The instance should be constructed from the class row (number=42).

Where

This came up in review of PR #7203 (#7203 (comment)). It should be fixed after #7149 and #7192 merge, because they rework the class-row and method-row pairing and instance construction for exactly this shape.

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

    blockedbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions