-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Given an enum type E, a long-backed enumtype El and a value of type E called e then Expression.Convert() will be treated differently in the compiler and the interpreter.
// comparable numerical value to e on all
Expression.Convert(Expression.Constant(e, typeof(E)), typeof(El))
// InvalidCastException in compiler.
// comparable numerical value to e in interpreter
Expression.Convert(Expression.Constant(e, typeof(object)), typeof(El))
Expression.Convert(Expression.Constant(e, typeof(Enum)), typeof(El))
// InvalidCastException in compiler.
// ArgumentException in interpreter.
Expression.Convert(Expression.Constant("hello"), typeof(El))Aside from the compiler winning on the grounds of precedence, it would appear to be correct on each count here, with the ArgumentException being plainly wrong. There is a bit of a risk to fixing the second case, as it could cause a throw in working code, though it's perhaps better to nip it in the bud.
Reactions are currently unavailable