Fix equality comparison type issue

- Compiling a function calling Internal.IntrinsicSupport.EqualityComparerHelpers.StructOnlyEquals<T> from a function that is itself generic on T where T is Nullable<SomeGenericStructWhichImplementsIEQuatable<__Canon>> produces an internal compiler error
- The issue is that instantiating a method of Canon isn't actually permitted to be a "real, callable" instantiation
- Fix by changing the "default" variant of StructOnlyEquals to depend on EqualityComparer<T> which is known to work (by using universal generics)
- Then add a variant for just using the Equals function
- Change the compiler to use the "Normal" variant most of the time
- Except for the newly discovered problematic case which can fall back to the slower, but semantically correct EqualityComparar<T> path

[tfs-changeset: 1711845]
This commit is contained in:
David Wrighton 2018-08-24 16:04:43 -07:00
Родитель 1f0ab27dc2
Коммит 31768b86b6
2 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -225,6 +225,10 @@ namespace Internal.IL
{
methodToCall = helperType.GetKnownMethod("StructOnlyEqualsIEquatable", null).MakeInstantiatedMethod(elementType);
}
else
{
methodToCall = helperType.GetKnownMethod("StructOnlyNormalEquals", null).MakeInstantiatedMethod(elementType);
}
if (methodToCall != null)
{

Просмотреть файл

@ -195,10 +195,15 @@ namespace Internal.IntrinsicSupport
#endif
}
private static bool StructOnlyNormalEquals<T>(T left, T right)
{
return left.Equals(right);
}
[Intrinsic]
internal static bool StructOnlyEquals<T>(T left, T right)
{
return left.Equals(right);
return EqualityComparer<T>.Default.Equals(left, right);
}
}
}