Add specs for regex literal expansion #13253
Merged
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.
This is a useful addition in general and particularly prepares for #13252
Edit: Also discovers and fixes a bug (?) introduced in #13223.
Previous to #13223, the base type of
Regex::Options
was the defaultInt32
. That PR changed it toUInt64
to gain more space.The parser creates an instance of
Regex::Options
from the modifier flags of a regex literal. When the compiler expands them, the option value is expressed by the base type value of theRegex::Options
type. The resulting number literal is typed, so the expression for theMULTILINE
options value would change from::Regex::Options.new(6)
to::Regex::Options.new(6_u64)
.Now this isn't an immediate problem when the base type of
Regex::Options
in the compiler and stdlib align. And even if they don't, autocasting of integer literals should allow the generated code to be compatible with olderRegex::Options
implementations withInt32
base type.Still, I think it's better to avoid such unintended side effects and keep the generated code consistent until we explicitly chose to change it for good as discussed in #13252.
The different domain range of
Int32
andUInt64
is irrelevant for this because the compiler only handles the three modifiers and the biggest integer value needed to represent them is15
(forimx
).