Skip to content

Source-gen emits typeof(dynamic) for dynamic test parameters (CS1962) #7165

Closed

Description

@thomhurst

What happens

A test method with a dynamic parameter does not compile in source-gen mode. The generated parameter metadata uses typeof(dynamic), which is error CS1962 ("The typeof operator cannot be used on the dynamic type"):

MyTests_OverloadTests__TestSource.g.cs(528,64): error CS1962: The typeof operator cannot be used on the dynamic type
    global::TUnit.Core.ParameterMetadataFactory.Create(typeof(dynamic), "value", new global::TUnit.Core.ConcreteType(typeof(dynamic)), false)

Repro

public class Tests
{
    [Test]
    [Arguments("x")]
    public void Takes_Dynamic(dynamic value) { }
}

Build with the source generator enabled (the default). Found while checking a review finding on #7148 (OmittedOptionalOverloadCompilationTests with a dynamic parameter).

Expected

dynamic is object at runtime, so the generator should emit typeof(object) wherever it writes typeof(<parameter type>) (parameter metadata, ConcreteType, and anywhere else a type is rendered inside typeof). Reflection mode already sees object for these parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions