Skip to content

Infer generic method arguments from instance data sources on generic classes #7628

Closed

Description

@thomhurst

Instance method data sources currently fail to infer generic test method arguments in source-generated discovery; generic classes can silently lose tests. Restore inference from declared row types and report constraint failures consistently with reflection discovery.

Scope

Own the instance-source recognition, explicit method type precedence, concrete-class source grouping/retry and uninferred-source diagnostics in src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs. Own the relevant generic-class and instance-source cases in tests/TUnit.Core.SourceGenerator.Tests/InstanceMethodTypeInferenceTests.cs and its verified snapshot, tests/TUnit.TestProject/Bugs/_7222/GenericInstanceSourceTests.cs and InstanceSourceConstraintViolationTests.cs, and tests/TUnit.Engine.Tests/Issue7222Tests.cs.

Reuse the relevant commits from preserved branch issue-7351-instance-inference (PR #7620, head 3e16914), extracting only this scope. Keep tuple conversion changes in the separate sibling deliverable.

Acceptance

Both modes retain static and instance sources sharing a concrete class instantiation in either declaration order, respect explicit method types, retry inference after class arguments close, and report failed sources exactly once without suppressing successful sources. Cover valid and invalid constraints, explicit and constructor-inferred classes, and a source covered by another successful pairing. Run generator snapshots and targeted fixtures in both modes; leave engine suite execution to CI. No blocking review finding targets this independent portion; retain the class-retry regressions discussed in #7620.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High: significant user-facing bug, fix soonbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions