Skip to content

Reflection rejects convertible types for a repeated generic tuple parameter #7481

Open

Description

@thomhurst

Summary

A generic test accepting (T, T) passes with a method data source returning (int, long) in source-generated mode but fails during generic inference in reflection mode. Users switching discovery modes cannot run the same convertible tuple data.

Reproduction

Add this class to a TUnit test project:

public class TupleInferenceTests
{
    public static (int, long) Row() => (1, 2L);
    [Test, MethodDataSource(nameof(Row))]
    public void Test<T>((T, T) row) { }
}

Run the class normally, then with --reflection.

Expected and actual

Both modes should infer a compatible type and bind the row consistently. Source-generated mode passes; reflection mode throws GenericTypeResolutionException: Type mismatch: Cannot use argument of type 'ValueTuple2' for parameter of type 'ValueTuple2'.

TestGenericTypeResolver.TryInferTypeMapping rejects repeated type parameters unless their inferred types are exactly equal. It does not combine the numeric bounds as the generator does. Correcting inference also requires converting the preserved tuple to the closed parameter type before invocation.

Environment

.NET SDK 10.0.403, net10.0, macOS arm64. Reproduced at merge base 67870ed and on e1d8214; this predates #7469. Both generated probe cases passed on the PR head; this case failed in reflection mode on both commits.

Remaining work and acceptance criteria

Depends on #7482 for normalization of preserved tuple rows after generic inference. This issue owns repeated-type inference; reuse the binding fix from #7482 rather than implementing a second conversion path.

Found while reviewing #7469.

Activity

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

    @thomhurst
    OwnerAuthor

    Triaged against origin/main at 1f70564. TestGenericTypeResolver.TryInferTypeMapping still requires exact equality for repeated generic mappings. Even once inference selects long, (int, long) must be rebuilt as (long, long) before reflection invocation. Added native blocked-by #7482 and narrowed this issue to inference, reusing #7482 for binding. Both bugs remain open; #7469 explicitly tracks them as separate follow-ups.

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