Support Match
nodes with non-int-literals in the back-end.
#3842
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.
See scala/scala#8451 upstream (not yet merged, but fully approved)
Since Scala 2.13.2, the pattern matcher will keep
Match
nodes that match onString
s andnull
s as is, to be desugared later incleanup
. This was implemented upstream in scala/scala#8451We implement a more general translation that will accept any kind of scalac
Literal
. If the scrutinee is an integer and all cases are int literals, we emit ajs.Match
as before. Otherwise, we emit anif..else
chain with===
comparisons.Locally tested with:
As noted at scala/scala#8451 (comment), 0.6.x already works out of the box with the change upstream.
It actually raises the question whether we should revert the design of our
js.Match
to accept any kind ofjs.Literal
s and really iron out the linker (notably for IR literals that are not JS literals, such asClassOf
andLongLiteral
) instead of changing the compiler back-end. This PR implements the less disruptive change.