Skip to content

Preserve nullable class discovery parity and constructed-struct constructor precedence #7611

Closed

Description

@thomhurst

Summary

Nullable generic class method-source inference must discover the same tests in generated and reflection modes while preserving constructor-supplied class types. Extract the discovery correction from #7591 and fix the remaining constructor-precedence discrepancy before opening its replacement PR.

Proposal

Reuse branch issue-7573-nullable-analyzer at 36c8723ae14871d458537bdc8f3daf4dee479808. Own src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs, src/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs, tests/TUnit.Core.SourceGenerator.Tests/NullableClassMethodRowsTests.cs and its verified snapshot, and tests/TUnit.TestProject/Bugs/_7573/NullableClassMethodRows.cs. Reuse only relevant changes against current main; coordinate overlapping discovery work with #7597. Keep analyzer files in the sibling analyzer issue. Refresh STA snapshots only if still needed on the new base and review each difference.

Blocking finding to resolve

#7591 (comment) : ContainsNullableClassParameter recognizes Nullable but misses Nullable<KeyValuePair<T,int>>. For [Arguments(1d)] class Tests(T seed), Run(KeyValuePair<T,int>?[] values), and an own-class IEnumerable<Func<KeyValuePair<int,int>[]>> source returning a null array, generated discovery adds Tests beside constructor-supplied Tests; reflection retains only Tests. Recognize class parameters inside nullable constructed types and pin constructor precedence in both modes.

Acceptance criteria

  • Fix that finding with a shared regression that discovers only the constructor-supplied class in both modes.
  • Preserve the original 35-case nullable discovery coverage: scalar/factory/tuple/array rows, nullable constructed structs, explicit types, scoped multiple sources, nested constructor precedence, partial constructor rows and constraint-valid row-value fallback.
  • Keep existing last-occurrence inference behavior and exclude unresolved rows, generic sources, argument-taking sources and external generic providers.
  • Run targeted execution in both modes, affected full generator snapshot suite, and Native AOT publish/execution when changing reflection. Engine tests remain CI-only. Review and commit intentional verified snapshots only.
  • Avoid suppressing TUnit0001 globally; use the analyzer sibling when available or narrowly suppress the known pending diagnostic in these regression fixtures until it lands. Each part must remain independently mergeable.

Parent: #7573. Split because #7591 exceeded the automated review budget. Policy consolidation remains #7377.

Activity

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

    @thomhurst
    OwnerAuthor

    Claimed under issue-7611. Extracting only the discovery files and shared nullable fixtures from 36c8723, with the constructed-nullable constructor-precedence regression. #7610 / #7613 retains analyzer ownership. This change overlaps the discovery files named by #7597; its lock is currently free, and this replacement will identify the overlap for rebasing the later discovery adapter 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

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions