@@ -268,31 +268,34 @@ private[emitter] final class SJSGen(
268
268
269
269
def genAsInstanceOf (expr : Tree , tpe : Type )(
270
270
implicit moduleContext : ModuleContext , globalKnowledge : GlobalKnowledge ,
271
- pos : Position ): Tree = {
271
+ pos : Position ): WithGlobals [ Tree ] = {
272
272
import TreeDSL ._
273
273
274
+ // Local short-hand of WithGlobals(...)
275
+ def wg (tree : Tree ): WithGlobals [Tree ] = WithGlobals (tree)
276
+
274
277
if (semantics.asInstanceOfs == CheckedBehavior .Unchecked ) {
275
278
tpe match {
276
279
case _:ClassType | _:ArrayType | AnyType =>
277
- expr
280
+ wg( expr)
278
281
279
- case UndefType => Block (expr, Undefined ())
280
- case BooleanType => ! (! expr)
281
- case CharType => genCallHelper(" uC" , expr)
282
- case ByteType | ShortType | IntType => expr | 0
283
- case LongType => genCallHelper(" uJ" , expr)
284
- case DoubleType => UnaryOp (irt.JSUnaryOp .+ , expr)
285
- case StringType => expr || StringLiteral (" " )
282
+ case UndefType => wg( Block (expr, Undefined () ))
283
+ case BooleanType => wg( ! (! expr) )
284
+ case CharType => wg( genCallHelper(" uC" , expr) )
285
+ case ByteType | ShortType | IntType => wg( expr | 0 )
286
+ case LongType => wg( genCallHelper(" uJ" , expr) )
287
+ case DoubleType => wg( UnaryOp (irt.JSUnaryOp .+ , expr) )
288
+ case StringType => wg( expr || StringLiteral (" " ) )
286
289
287
290
case FloatType =>
288
- if (semantics.strictFloats) genCallHelper( " fround " , expr)
289
- else UnaryOp (irt.JSUnaryOp .+ , expr)
291
+ if (semantics.strictFloats) genCallPolyfillableBuiltin( FroundBuiltin , expr)
292
+ else wg( UnaryOp (irt.JSUnaryOp .+ , expr) )
290
293
291
294
case NoType | NullType | NothingType | _:RecordType =>
292
295
throw new AssertionError (s " Unexpected type $tpe in genAsInstanceOf " )
293
296
}
294
297
} else {
295
- tpe match {
298
+ val resultTree = tpe match {
296
299
case ClassType (ObjectClass ) =>
297
300
expr
298
301
case ClassType (className) =>
@@ -316,6 +319,8 @@ private[emitter] final class SJSGen(
316
319
case NoType | NullType | NothingType | _:RecordType =>
317
320
throw new AssertionError (s " Unexpected type $tpe in genAsInstanceOf " )
318
321
}
322
+
323
+ wg(resultTree)
319
324
}
320
325
}
321
326
0 commit comments