Skip to content

parser: preserve the enum type in conversions - #16

Merged
rameel merged 1 commit into
mainfrom
parser/enum-conversion
Nov 17, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/enum-conversion

Conversation

@rameel

@rameel rameel commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Converting an enum with :> boxed its underlying value instead of the enum. DayOfWeek.Friday :> object produced the Int32 5, so its ToString() returned "5" instead of "Friday", and 1 :> DayOfWeek :> object produced 1. The unary operator builder converted every enum operand to its underlying type before the operation, including a conversion.

This PR passes the enum itself to a conversion. Arithmetic and bitwise operators still work on the underlying type, and conversions of an enum to a numeric type produce the same values as before.

The unary operator builder converted an enum operand to its underlying
type before every operation, including a conversion. Converting an
enum to object therefore boxed its underlying value:
'DayOfWeek.Friday :> object' produced the Int32 5, and its ToString()
returned "5" instead of "Friday".

Pass the enum itself to a conversion, and convert it to the underlying
type only for arithmetic and bitwise operators.
@rameel
rameel merged commit 74935a6 into main Nov 17, 2026
1 check passed
@rameel
rameel deleted the parser/enum-conversion branch November 17, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant