Skip to content

Generic Parameters With Default Value Are Generated As Nullable Set to null #200

@JasonBock

Description

@JasonBock

To reproduce:

public interface IGenericDefault
{
  void Setup<T>(T initialValue = default(T));
}

Rocks generates it like this:

public void Setup<T>(T? @initialValue = null)

This gives:

error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'TProperty'

As well as on the extension method:

@initialValue.Transform(null)

It's trying to transform T from null and that isn't allowed.

This was found on Moq.Protected.IProtectedAsMock<,>.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions