Skip to content

Generated invokers fail to convert nested tuple elements for generic tests #7485

Closed

Description

@thomhurst

Summary

A method data source returning (int, (int, string)) cannot bind to a generic test parameter (T, (int, object)) in source-generated mode. C# permits the element conversions, but the generated invoker throws InvalidCastException on the inner tuple.

Reproduction

public class NestedTupleBindingTests
{
    public static (int, (int, string)) Row() => (1, (2, "nested"));
    [Test, MethodDataSource(nameof(Row))]
    public void Test<T>((T, (int, object)) row) { }
}

Run this class in source-generated mode with a targeted treenode filter.

Expected and actual

The test should run with T = int and retain the tuple elements. Instead, CastHelper.Cast<T> in the generated invoker tries to cast ValueTuple<int, string> directly to ValueTuple<int, object> and fails. Generate recursive tuple element conversions for nested tuple parameters.

Environment

.NET SDK 10.0.403, net10.0, macOS arm64. Reproduced against main 9100521 while implementing #7482; the generated path is unchanged by that reflection-only fix. Distinct from initializer mutations in #7484 and reference-tuple analyzer diagnostics in #7480.

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