Skip to content

Generic class row that infers no type argument: reflection parity beside other data sources #7390

Open

Description

@thomhurst

Split from #7337, which went over the issue-pr-loop rework budget. The core rule for type-free class rows from #7389 shipped in #7392 (ca4437c718). This issue covers only the remaining parity work beside other data sources; it has no open prerequisite. It brings reflection mode in line with source-generated mode when a type-free class [Arguments] row sits beside other data sources.

Scope (reflection must match the generator)

With [Arguments(42)] on C<T>(int number), as the type-free class row:

  • A class [MethodDataSource] that infers the same type does not replace the type-free rows (AddTypeFreeClassRowsToGroups).
  • Method [MethodDataSource], typed [ClassDataSource<...>], and parameter data attributes infer instantiations beside type-free rows. They are not scoped to one instantiation, including when no method parameter uses T, and including beside [GenerateGenericTest] (even one whose type is rejected).
  • A method-row constraint check skips CancellationToken and uses discovery's type mapping, so a T[] row that violates the constraints fails instead of disappearing.
  • Open blocking finding (Codex P1 on 3328846, thread): with Run<U>(T value, U other) carrying both [ClassDataSource<int, long>] and [ClassDataSource<int, short>], reflection slices the inferred types down to the class arguments. AddSourceInstantiation then drops the second source as a duplicate, and C<int>.Run<short> is lost. The generator keeps both because its instantiation keys include the method type arguments. Key instantiations by class and method types, or merge their source selections.

Current code and reusable branch code

Audited against origin/main at d87516cb9c: DiscoverGenericTestsAsync splits type-free class rows, but does not add them back to matching class-source groups. BuildTestsForMethodRowsWithoutClassRow still derives additional instantiations only from method argument rows. The core behavior shipped by #7392 is not part of this issue.

AddTypeFreeClassRowsToGroups, AddSourceInstantiation, and InferClassTypeArgumentsFromMethodRow below refer to the reusable #7337 branch implementation, not helpers already present on main. Preserve the reported combined class/method-type P1 regression when adapting that implementation.

Files

  • TUnit.Engine/Discovery/ReflectionTestDataCollector.cs (DiscoverGenericTestsAsync, AddSourceInstantiation, BuildTestsForMethodRowsWithoutClassRow, InferClassTypeArgumentsFromMethodRow).
  • ReflectionGenericConstraintViolations.cs.
  • Tests: the matching _7209 TestProject classes (TypeFreeClassRowBesideOtherSource, ...WithUninferredMethodSource, ...WithTypedMethodSource, ...ArrayConstraintViolation, ...WithInferringRowAndTypedSource, ...WithTwoInferringMethodSources, ...WithGenerateGenericTestAnd*, ...WithTypedSourceAndNonGenericParameter, ...WithCombinedTypedSource, plus a new class for the P1), the Issue7209Tests rows, and the Tests7209 snapshot.

Reusable commits

Branch issue-7209-generic-class-row-no-type-arg (PR #7337): 78e0a1df1e, a98ad71f7e, dd94cd15e1, c807147127, 948d4b126c, 73e13a0065, c04450e590, 6a97bb8661, 0bfe40862c, the data-source half of bc7255a35a, 3e48ddde33, 6ec926b683, 332884605e.

Keep the PR small. If its review keeps finding new combinations, file them as sibling issues under #7209 rather than growing this one. Consider #7371 (one shared set of inference rules) before adding more special cases to the flag bookkeeping in DiscoverGenericTestsAsync. Edge-case tests for the rule itself are tracked in #7387.

Acceptance criteria

  • Each class above, and the P1 case, runs the same tests in both modes.
  • TUnit.TestProject /**[EngineTest=Pass] shows 0 failures in both modes, and the generator snapshot has been reviewed.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 2, 2026
  2. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    #7392 (ca4437c) merged the core rule and constructor binding from #7389. Removed that completed prerequisite and detached this remaining parity work from #7209, which now has only this open child. This issue retains the remaining scope and acceptance criteria; it can be claimed independently.

  3. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Triage against d87516cb9c: #7392 already delivers the core rule; the remaining mixed-source parity work is still open. Updated the body to distinguish current main from helper names in the reusable #7337 branch. No open prerequisite is needed.

  4. thomhurst commented on Nov 4, 2026

    @thomhurst
    OwnerAuthor

    Two nonblocking CodeRabbit findings on #7571 confirm the uninferable-method-source variant belongs in this type-free-row follow-up: #7571 (comment) and #7571 (comment).

    For [Arguments(42)] class C<T>(int number) with IEnumerable<object[]> Rows() and [Test, MethodDataSource(nameof(Rows))] void Run(T value), no source supplies T. Expected: one discovery failure naming Rows, in both modes. Generator head df2cf32 uses hasAnyClassDataSource rather than classTypeArgumentsSupplied in ReportsUninferredMethodSource; reflection's BuildTestsForMethodRowsWithoutClassRow skips null rowTypeArguments without emitting a failure. Verified both paths against the code; main does not yet contain #7571's new policy. Include the uninferable variant in the both-mode parity/diagnostic coverage already scoped here, retaining the non-generic-method filter and explicit-type fallback.

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