Rocks icon indicating copy to clipboard operation
Rocks copied to clipboard

Nested Generic Types are Not Being Handled Correctly

Open JasonBock opened this issue 1 year ago • 1 comments

To Reproduce

#nullable enable

using Rocks;
using System;
		
[assembly: Rock(typeof(IUseGeneric<>), BuildType.Create)]

public interface IUseGeneric<T>
{
  IAmGeneric<T> Calculate();	

  public interface IAmGeneric<T2> { }
}

Expected behavior The mock is created as expected.

Actual behavior Errors occurs:

Error - Id: CS0305, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(17,55): error CS0305: Using the generic type 'IUseGeneric<T>' requires 1 type arguments
Error - Id: CS0305, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(17,91): error CS0305: Using the generic type 'IUseGeneric<T>' requires 1 type arguments
Error - Id: CS0305, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(45,18): error CS0305: Using the generic type 'IUseGeneric<T>' requires 1 type arguments
Error - Id: CS0305, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(107,133): error CS0305: Using the generic type 'IUseGeneric<T>' requires 1 type arguments
Error - Id: CS0305, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(107,169): error CS0305: Using the generic type 'IUseGeneric<T>' requires 1 type arguments
Error - Id: CS0738, Description: Rocks\Rocks.RockGenerator\IUseGenericT_Rock_Create.g.cs(37,5): error CS0738: 'IUseGenericCreateExpectations<T>.Mock' does not implement interface member 'IUseGeneric<T>.Calculate()'. 'IUseGenericCreateExpectations<T>.Mock.Calculate()' cannot implement 'IUseGeneric<T>.Calculate()' because it does not have the matching return type of 'IUseGeneric<T>.IAmGeneric<T>'.

Additional context Since the return type is generic and nested within another generic type, Rocks isn't putting in the generic parameter correctly for the outer type. Need to ensure that Rocks always generates the right type name with the right number of generic parameters no matter what the nesting is. This should be for property types, parameters, return values - anywhere a type name is needed.

This was found on Microsoft.EntityFrameworkCore.Query.Internal.PrecompiledQueryContext<>

JasonBock avatar Aug 15 '24 16:08 JasonBock

I believe the issue lies within TypeReferenceModel.BuildName() and how it handles generics.

JasonBock avatar Aug 20 '24 12:08 JasonBock