Below is just a pseudo code to demonstrate the issue.
public struct ValueHolder<T> : IEquatable<ValueHolder<T>>
{
public T value;
public bool Equals(ValueHolder<T> other)
=> this.value.Equals(other.value);
}
public struct A : IEquatable<A>
{
public bool Equals(A other)
{
UnityEngine.Debug.Log("Equals(A)");
return true;
}
public override bool Equals(object obj)
{
UnityEngine.Debug.Log("Equals(object)");
return false;
}
}
ValueHolder<A> a = default;
ValueHolder<A> b = default;
a.Equals(b);
- Currently the last line will print
"Equals(object)". - To print
"Equals(A)", we have to constraintTtoIEquatable<T>. - However,
ValueHolder<T>is a example of a multi-purpose type,Tcan't be constrained to anything.
Given that equality comparison permeats every codebase and it's not always possible to write explicit code path (e.g. NativeHashMap requires TKey to be IEquatable) or maintain another Burst-compatible version of some types, could Burst automatically prioritize Equals(T) when possible?