Skip to content

Exact Match With Non-Virtual Member #247

@JasonBock

Description

@JasonBock

To reproduce:

var code =
	"""
	using Rocks;

	public class TypeNode { }

	public interface IIRTypeContext { }

	public interface ITypeConverter<TType>
		where TType : TypeNode
	{
		TypeNode ConvertType<TTypeContext>(TTypeContext typeContext, TType type)
			where TTypeContext : IIRTypeContext;
	}

	public abstract class TypeConverter<TType> : ITypeConverter<TypeNode>
		where TType : TypeNode
	{
		protected abstract TypeNode ConvertType<TTypeContext>(
			TTypeContext typeContext,
			TType type)
			where TTypeContext : IIRTypeContext;

		public TypeNode ConvertType<TTypeContext>(
			TTypeContext typeContext,
			TypeNode type)
			where TTypeContext : IIRTypeContext => new();
	}

	public static class Test
	{
		public static void Generate()
		{
			var rock = Rock.Create<TypeConverter<TypeNode>>();
		}
	}
	""";

This will lead to the following error:

error CS0462: The inherited members 'TypeConverter<TType>.ConvertType<TTypeContext>(TTypeContext, TType)' and 'TypeConverter<TType>.ConvertType<TTypeContext>(TTypeContext, TypeNode)' have the same signature in type 'CreateExpectationsOfTypeConverterOfTypeNodeExtensions.RockTypeConverterOfTypeNode', so they cannot be overridden

This is pretty interesting, in that you have to override the abstract member, but by doing that, you collide with a non-virtual member that exists as an exact match. So, in this case, the type cannot be mocked. Note that if a subtype of TypeNode was passed to TypeConverter<>, this would not be an issue.

This was found on ILGPU.IR.Types.TypeConverter<>.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions