sealed case class Match(selector: Tree, cases: List[(List[MatchableLiteral], Tree)], default: Tree)(tpe: Type)(implicit pos: Position) extends Tree with Product with Serializable
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.
- Alphabetic
- By Inheritance
- Match
- Serializable
- Product
- Equals
- Tree
- TreeOrJSSpread
- IRNode
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- val cases: List[(List[MatchableLiteral], Tree)]
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- val default: Tree
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- implicit val pos: Position
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- val selector: Tree
- def show: String
- Definition Classes
- IRNode
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- val tpe: Type
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()