Match
A break-free switch (without fallthrough behavior).
Unlike a JavaScript switch, it can be used in expression position.
It supports alternatives explicitly (hence the List[MatchableLiteral]
in cases), whereas in a switch one would use the fallthrough behavior to
implement alternatives.
(This is not a pattern matching construct like in Scala.)
The selector must be either an int
(IntType
) or a java.lang.String
.
The cases can be any MatchableLiteral
, even if they do not make sense
for the type of the selecter (they simply will never match).
Because +0.0 === -0.0
in JavaScript, and because those semantics are
used in a JS switch
, we have to prevent the selector from ever being
-0.0
. Otherwise, it would be matched by a case IntLiteral(0)
. At the
same time, we must allow at least int
and java.lang.String
to support
all switchable match
es from Scala. Since the latter two have no common
super type that does not allow -0.0
, we really have to special-case
those two types.
This is also why we restrict MatchableLiteral
s to IntLiteral
,
StringLiteral
and Null
. Allowing more cases would only make IR
checking more complicated, without bringing any added value.
Attributes
- Graph
- Supertypes
- trait Serializabletrait Producttrait Equalsclass Treetrait TreeOrJSSpreadclass IRNodeclass Objecttrait Matchableclass Any