Skip to content

Infer generic class types from class MethodDataSource rows using shared runtime support #7446

Open

Description

@thomhurst

A generic test class whose only type information comes from a class-level MethodDataSource silently disappears in generated discovery. Enable declared-row and constructor-based type inference once the sibling runtime support is merged, so both discovery modes run the same tests or report an actionable discovery failure.

Scope and owned files

  • src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs and src/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/InstanceFactoryGenerator.cs.
  • tests/TUnit.Core.SourceGenerator.Tests/Bugs/7333/Tests7333.cs, affected generator snapshots, tests/TUnit.TestProject/Bugs/_7333/ClassMethodDataSourceInferenceTests.cs, _7161/ClassDataForMethodRowInstantiationTests.cs, and tests/TUnit.Engine.Tests/Issue7333Tests.cs / Issue7208Tests.cs. Reconcile runtime regressions introduced by the prerequisite rather than duplicating them.
  • Reuse preserved branch issue-7333-class-method-source, head df168fa58f32f0ef591b731330cf2407b4922fc9.

Acceptance criteria

Split because #7422 reached 21 automated review rounds with a new blocking parity finding. Parent #7333 remains open until both parts deliver its acceptance criteria.

Activity

  1. added
    bugSomething isn't working
    P1High: significant user-facing bug, fix soon
    on Nov 3, 2026
  2. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Triaged against origin/main at 87d2a30. The inference changes and ConfigureInferredSource runtime support from closed, unmerged #7422 are still absent. Both sibling issues remain necessary; #7425 covers diagnostics but does not deliver class-source inference. Removed the redundant blocked label; the native blocked_by dependency on #7445 remains authoritative.

  3. thomhurst commented on Nov 4, 2026

    @thomhurst
    OwnerAuthor

    Additional row-partition parity case found while fixing #7518's method-provider retention. A declared interface constructor source plus a concrete method source produces an extra inferred class test in generated discovery. Reflection only runs the explicitly requested interface instantiation.

    [GenerateGenericTest(typeof(IComparable))]
    [MethodDataSource(nameof(ConstructorRows))]
    public class C<T>(T value)
    {
        public static IEnumerable<IComparable> ConstructorRows() => [42];
        public static IEnumerable<int> MethodRows() => [43];
        [Test, MethodDataSource(nameof(MethodRows))]
        public void Test(T argument) { }
    }

    SDK 10.0.403, net10.0, macOS arm64. At #7518 head 4a5e436, generated discovery emits C (passing) and C (missing method arguments); reflection emits only the passing C. The provider-retention fix repairs C, but the extra generated C remains. The same difference occurs with a DataSourceGeneratorAttribute method provider. Expected: both modes run the same closed instantiations.

    Reproduce with the ExplicitCompatibleMethodRows and ExplicitCompatibleTypedMethodRows fixtures added to tests/TUnit.TestProject/Bugs/_7490/Tests.cs in #7518: run net10.0 with --treenode-filter '//TUnit.TestProject.Bugs._7490/ExplicitCompatibleMethodRows/*', then add --reflection. Please cover these declared-source/explicit-type combinations in this issue's class-source inference and partition work.

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

    P1High: significant user-facing bug, fix soonbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions