Skip to content

Source-gen runs only one class source when two class-level sources infer the same generic class instantiation; reflection runs both #7335

Closed

Description

@thomhurst

What happens

Two class-level sources infer the same instantiation of a generic class, but source-gen runs only one of them:

public class IntGenerator : DataSourceGeneratorAttribute<int>
{
    protected override IEnumerable<Func<int>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata)
    {
        yield return () => 7;
    }
}

[Arguments(1)]
[IntGenerator]
public class ClassRowsSharingInstantiation<T>(T value)
{
    [Test]
    [Arguments(2)]
    public void Test(T arg) { }
}
  • --reflection: C<int> runs with both class rows, so 2 tests (ctor 1 and ctor 7).
  • source-gen: the C<int> entry is scoped to the [Arguments(1)] row only, so 1 test (ctor 1).

This was reproduced on main (d43977c) in tests/TUnit.TestProject. It was first noted in #7208 ("Related difference"), which was found while handling a review thread on #7149, and it moved here so that #7208 covers only the class-level [MethodDataSource] fix.

Expected

Both modes run every class row that infers the instantiation: 2 tests, ctor 1 and ctor 7.

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