Skip to content

Commit 5092141

Browse files
sjrdsmarter
authored andcommitted
Properly type js.If and js.TryCatch in statement position
In statement position, they must always be typed as NoType, since their children might be typed as such. Forward port of scala-js/scala-js@e440de9
1 parent 397fb2f commit 5092141

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,12 @@ class JSCodeGen()(using genCtx: Context) {
16211621
}
16221622

16231623
case If(cond, thenp, elsep) =>
1624+
val tpe =
1625+
if (isStat) jstpe.NoType
1626+
else toIRType(tree.tpe)
1627+
16241628
js.If(genExpr(cond), genStatOrExpr(thenp, isStat),
1625-
genStatOrExpr(elsep, isStat))(toIRType(tree.tpe))
1629+
genStatOrExpr(elsep, isStat))(tpe)
16261630

16271631
case Labeled(bind, expr) =>
16281632
js.Labeled(encodeLabelSym(bind.symbol), toIRType(tree.tpe), genStatOrExpr(expr, isStat))
@@ -1857,7 +1861,10 @@ class JSCodeGen()(using genCtx: Context) {
18571861
val Try(block, catches, finalizer) = tree
18581862

18591863
val blockAST = genStatOrExpr(block, isStat)
1860-
val resultType = toIRType(tree.tpe)
1864+
1865+
val resultType =
1866+
if (isStat) jstpe.NoType
1867+
else toIRType(tree.tpe)
18611868

18621869
val handled =
18631870
if (catches.isEmpty) blockAST

0 commit comments

Comments
 (0)