10000 Fix #4442: Properly type js.If and js.TryCatch in statement position · gzm0/scala-js@e440de9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e440de9

Browse files
gzm0sjrd
authored andcommitted
Fix scala-js#4442: 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. We condition the deserialization hack introduced in the parent commit so that it only applies to old code.
1 parent 3601272 commit e440de9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,8 +2225,12 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
22252225
}
22262226

22272227
case If(cond, thenp, elsep) =>
2228+
val tpe =
2229+
if (isStat) jstpe.NoType
2230+
else toIRType(tree.tpe)
2231+
22282232
js.If(genExpr(cond), genStatOrExpr(thenp, isStat),
2229-
genStatOrExpr(elsep, isStat))(toIRType(tree.tpe))
2233+
genStatOrExpr(elsep, isStat))(tpe)
22302234

22312235
case Return(expr) =>
22322236
js.Return(toIRType(expr.tpe) match {
@@ -2690,7 +2694,10 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
26902694
val Try(block, catches, finalizer) = tree
26912695

26922696
val blockAST = gen B3D1 StatOrExpr(block, isStat)
2693-
val resultType = toIRType(tree.tpe)
2697+
2698+
val resultType =
2699+
if (isStat) jstpe.NoType
2700+
else toIRType(tree.tpe)
26942701

26952702
val handled =
26962703
if (catches.isEmpty) blockAST

ir/shared/src/main/scala/org/scalajs/ir/Serializers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ object Serializers {
17901790

17911791
val use14: Boolean = use13 || sourceVersion == "1.4"
17921792

1793-
val use15: Boolean = true // use14 || sourceVersion == "1.5"
1793+
val use15: Boolean = use14 || sourceVersion == "1.5"
17941794
}
17951795

17961796
/** Names needed for hacks. */

0 commit comments

Comments
 (0)
0