Skip to content

Expression.Convert() incorrect in interpreter with enum types. #16799

@JonHanna

Description

@JonHanna

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions