Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Make the logic handling folding of integer- and float-like conversion
more exhaustive and slightly simplify it. This fixes the internal issue
of literal-nodes having unexpected types, and it also fixes no range
error being reported at compile-time for some to-
char
conversion.Details
Folding conversions to integer, float, and bool types now considers all
valid source types, with unexpected types now being treated as a defect
instead of silently ignoring them. Named set constants are used for
this, with
tyChar
being included in the integer-like set, meaning thatto-
char
conversions are now properly subjected to range checks duringconstant folding.
For the integer-like branch handling, the logic is simplified to only
perform the range check in a single place, and the unnecessary
transition-to-
nkUIntLit
removed (newIntNodeType
already makes surethat the node has the correct kind based on the type).
In general, this is a step towards the type of a literal-node matching
its kind. Both the C and VM code generator use the node kind for
deciding whether a float literal is a 32-bit or 64-bit one, so the
float-literal-nodes produced by constant folding now having the correct
kind fixes a bug where the emitted float literals had the wrong target-
language type (see the fixed test
tfloats.nim
).