Skip to content

Multiple DIMs in Different Interfaces With the Same Name Causes Issues #374

@JasonBock

Description

@JasonBock

To Reproduce

Run this test code:

var code =
	"""
	using Rocks;
			
	[assembly: Rock(typeof(IAuditTrail<>), BuildType.Create | BuildType.Make)]
			
	public interface IAuditTrail
	{
		void Work() { }
	}

	public interface IAuditTrail<T>
		: IAuditTrail
	{
		void Perform() { }
	}
	""";

Expected behavior
Rocks generates code with no issues.

Actual behavior
The following diagnostics are generated:

error CS0102: The type 'IAuditTrailCreateExpectations<T>.Mock' already contains a definition for 'shimForIAuditTrail'
    
error CS0229: Ambiguity between 'IAuditTrailCreateExpectations<T>.Mock.shimForIAuditTrail' and 'IAuditTrailCreateExpectations<T>.Mock.shimForIAuditTrail'

Additional context
The problem is that Rocks doesn't generate unique names for the shim field names:

private sealed class Mock
	: global::IAuditTrail<T>
{
	private readonly global::IAuditTrail<T> shimForIAuditTrail;
	private readonly global::IAuditTrail shimForIAuditTrail;

	// ...
}

Looks like the generic type parameter names should be added, similar to what is done for the file names. Something like this:

private readonly global::IAuditTrail<T> shimForIAuditTrailT;

If there are multiple, just append them together, something like this:

private readonly global::IAuditTrail<T1, T2, T3> shimForIAuditTrailT1T2T3;

This was found on DotNext.IO, DotNext.IO.Log.IAuditTrail<>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions