Skip to content

Commit 03a47b4

Browse files
committed
Scala.js: Fix a codegen bug for switch matches in statement position.
The codegen chooses `jstpe.NoType` (`void`) over the declared type of a `Match` node. That is normally fine, except if the declared type was `Nothing`, in which case we must retain it, because the enclosing statement might be demanding an expression of type `Nothing`.
1 parent 90720cf commit 03a47b4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,9 +2277,11 @@ class JSCodeGen()(using genCtx: Context) {
22772277
abortMatch(s"Invalid selector type ${genSelector.tpe}")
22782278
}
22792279

2280-
val resultType =
2281-
if (isStat) jstpe.NoType
2282-
else toIRType(tree.tpe)
2280+
val resultType = toIRType(tree.tpe) match {
2281+
case jstpe.NothingType => jstpe.NothingType // must take priority over NoType below
2282+
case _ if isStat => jstpe.NoType
2283+
case resType => resType
2284+
}
22832285

22842286
var clauses: List[(List[js.Tree], js.Tree)] = Nil
22852287
var optDefaultClause: Option[js.Tree] = None

0 commit comments

Comments
 (0)