Catch without variable fails
Closed this issue · 0 comments
langsamu commented
Description
A variable is optional for a catch block:
try
{
}
catch (Exception)
{
}
But the comparer assumes the variable is set when determining whether two catch blocks are equal and when calculating the hash code for a catch block.
To reproduce
// Same expression twice to evade reference equality check
var x = Expression.TryCatch(Expression.Empty(), Expression.Catch(typeof(Exception), Expression.Empty()));
var y = Expression.TryCatch(Expression.Empty(), Expression.Catch(typeof(Exception), Expression.Empty()));
AssertAreEqual(x, y);
Resolution
These are the offending assumptions:
Replacing EqualsParameter
and GetHashCodeParameter
with Equals
and GetHashCode
respectively solves the problem.