Skip to content

Class-level [Arguments] numeric literals are rewritten using test method parameter types #7440

Closed

Description

@thomhurst

Summary

Source generation uses test method parameter types when emitting class-level [Arguments]. A decimal test parameter can therefore rewrite an integer constructor argument as a decimal literal, so a generic class with multiple class sources can fail constructor binding. Class arguments should be emitted against constructor parameters.

Reproduction

[Arguments(1)]
[IntRows]
public class C<T>(T value)
{
    [Test]
    [Arguments(2)]
    public void Run(decimal number) { }
}

public class IntRowsAttribute : DataSourceGeneratorAttribute<int>
{
    protected override IEnumerable<Func<int>> GenerateDataSources(DataGeneratorMetadata metadata)
        => [() => 7];
}

Inspect generated class data sources: GenerateArgumentsAttributeWithParameterTypes uses methodSymbol.Parameters for class attributes too, changing [Arguments(1)] to ArgumentsAttribute(1m). With multiple class sources the concrete factory calls Activator.CreateInstance(typeof(C<int>), args); a boxed decimal cannot bind to its int constructor.

Expected and actual

Class argument 1 remains an int, independent of the test method parameter types. Currently the emitter selects the decimal method parameter and appends m to the class argument. This is a code-inspection finding; the fixture above has not been executed locally.

Environment

TUnit source at dd388fc; the same emitter exists on main at c2d1660. See parameter selection and review.

Please bind class argument emission to constructor parameter types and add a generator snapshot plus execution coverage in both discovery modes.

Activity

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

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