Skip to content

Generic class with an empty typed class MethodDataSource gets an extra instantiation in source-generated mode only #7899

Done

Description

@thomhurst

Summary

A generic test class whose class-level [MethodDataSource] is typed as IEnumerable<string> but returns no rows, and whose test method is closed by [Arguments(1)], discovers two tests in source-generated mode but one in reflection mode. Source-generated mode adds a second instantiation, C<string>, from the declared element type of the empty class source, and runs Empty on it with no method arguments. Both modes should discover the same tests.

Reproduction

[MethodDataSource(nameof(Rows))]
public class C<T>(T value)
{
    public static IEnumerable<string> Rows() => [];

    [Test]
    [Arguments(1)]
    public void Empty(T arg) => _ = value;
}

Run with --treenode-filter "/*/*/C*/*", then repeat with --reflection.

Expected and actual

  • Expected: both modes discover the same instantiations and the same number of tests.
  • Actual: source-generated mode discovers 2 tests (Empty(1) on C<int>, and Empty with no arguments on C<string>); reflection mode discovers 1 (Empty(1) on C<int>).

Environment

  • main at 163db63, .NET SDK 10.0.403, net10.0, macOS arm64.

Seen while validating #7442. Which instantiation set is intended here, so both modes can be aligned to it?

Activity

  1. added
    bug
    on Nov 29, 2026
  2. added
    P2
    needs-human
    on Nov 29, 2026
  3. added 2 commits that reference this issue on Nov 29, 2026
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

    P2bugneeds-human

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions