Skip to content

Don't Emit Default Values for Optional Arguments on Methods Explicitly Implemented #225

@JasonBock

Description

@JasonBock

Here's the example:

using Rocks;
using System;
using System.Threading.Tasks;
			
namespace MockTests
{
	public struct SomeStruct { }

	public interface IRequest<T>
		where T : class
	{
		Task<T> Send(object values, SomeStruct someStruct = default);
		Task Send(T message, SomeStruct someStruct = default);
	}	
			
	public static class Test
	{
		public static void Generate()
		{
			var rock = Rock.Create<IRequest<object>>();
		}
	}
}

This will compile in a test, but there will be warnings for CS1066. Basically, the resulting mock is putting the default values in (note that it doesn't matter that it's default, just whatever the default value is) in for the method that is explicitly implemented. If warnings are errors, this will fail. (For more information, look here).

The fix looks like we just don't emit any default values for parameters on explicitly implemented methods (I'm guessing this is true for indexers as well).

This was found with MassTransist.IRequestClient<>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions