Skip to content

[ArgumentsSource] does not support ref struct #2842

@timcassell

Description

@timcassell

This works:

[Arguments(new int[] { 1, 2, 3 })]
public void Benchmark(Span<int> args) { }

But this errors:

[ArgumentsSource(nameof(GetArgs))]
public void Benchmark(Span<int> args) { }

public IEnumerable<object[]> GetArgs()
{
    yield return new object[] { new int[] { 1, 2, 3 } };
}

Ambiguous user defined conversions 'Span.implicit operator Span(ArraySegment)' and 'Span.implicit operator Span(int[]?)' when converting from 'object' to 'Span'

Looking at the generated code, it's because of this:

__argField0 = (System.Span<System.Int32>)BenchmarkDotNet.Parameters.ParameterExtractor.GetParameter(GetArgs(), 0);;

So the code generator should take into account the actual type of the element if the argument is a ref struct so that both attributes work the same (which it seems it already does partially, because the field type is correct, only the cast is incorrect).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions