Skip to content

Source-gen drops an [Arguments<T>] row on a generic test method when another row infers the same types; reflection runs it #7214

Open

Description

@thomhurst

What happens

On a generic test method, a typed data source such as [Arguments<int>(2)] that infers the same method type arguments as another row is dropped in source-generated mode. Reflection mode runs it.

public class ProbeNonGenericArgsOfT
{
    [Test]
    [Arguments(1)]
    [Arguments<int>(2)]
    public void Run<TMethod>(TMethod v) => Console.WriteLine($"{typeof(TMethod).Name} {v}");
}

Results on main (c4b9977, net10.0, Release):

  • source-gen: 1 test, Run<int>(1). The [Arguments<int>(2)] row never runs.
  • --reflection: 2 tests, Run<int>(1) and Run<int>(2).

On PR #7186 (fix/issue-7164-typed-source-generic-class), the same method on a generic class ([GenerateGenericTest(typeof(string))] class C<TClass>) gives the same split: 1 test in source-gen, 2 in reflection. On main that generic-class shape does not compile in source-gen (#7117).

Where (not yet traced)

The likely place is the source generator's per-method instantiation/row collection (TestMetadataGenerator.CollectConcreteInstantiations and the typed-source inference around InferTypesFromDataSourceAttribute). Note that ArgumentsAttribute<T> has the symbol Name "ArgumentsAttribute", the same as the non-generic [Arguments], which many generator checks compare against by name. Reflection mode tells them apart (is ArgumentsAttribute), so the two modes may classify this attribute differently.

Expected

Both modes run the same rows: here, 2 tests (Run<int>(1) and Run<int>(2)), as reflection mode does.

Found while reviewing PR #7186.

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions