Repository navigation
Description
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 usesT, and including beside[GenerateGenericTest](even one whose type is rejected). - A method-row constraint check skips
CancellationTokenand uses discovery's type mapping, so aT[]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.AddSourceInstantiationthen drops the second source as a duplicate, andC<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
_7209TestProject classes (TypeFreeClassRowBesideOtherSource,...WithUninferredMethodSource,...WithTypedMethodSource,...ArrayConstraintViolation,...WithInferringRowAndTypedSource,...WithTwoInferringMethodSources,...WithGenerateGenericTestAnd*,...WithTypedSourceAndNonGenericParameter,...WithCombinedTypedSource, plus a new class for the P1), theIssue7209Testsrows, and theTests7209snapshot.
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
fix(generic): bind class rows to the [TestConstructor] or first publi…
fix(generic): a type-free class [Arguments] row lets method rows infe…
thomhurst commentedon Nov 3, 2026
#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.
thomhurst commentedon Nov 3, 2026
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.thomhurst commentedon Nov 4, 2026
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)withIEnumerable<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.