@@ -268,31 +268,34 @@ private[emitter] final class SJSGen(
268268
269269 def genAsInstanceOf (expr : Tree , tpe : Type )(
270270 implicit moduleContext : ModuleContext , globalKnowledge : GlobalKnowledge ,
271- pos : Position ): Tree = {
271+ pos : Position ): WithGlobals [ Tree ] = {
272272 import TreeDSL ._
273273
274+ // Local short-hand of WithGlobals(...)
275+ def wg (tree : Tree ): WithGlobals [Tree ] = WithGlobals (tree)
276+
274277 if (semantics.asInstanceOfs == CheckedBehavior .Unchecked ) {
275278 tpe match {
276279 case _:ClassType | _:ArrayType | AnyType =>
277- expr
280+ wg( expr)
278281
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 (" " ) )
286289
287290 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) )
290293
291294 case NoType | NullType | NothingType | _:RecordType =>
292295 throw new AssertionError (s " Unexpected type $tpe in genAsInstanceOf " )
293296 }
294297 } else {
295- tpe match {
298+ val resultTree = tpe match {
296299 case ClassType (ObjectClass ) =>
297300 expr
298301 case ClassType (className) =>
@@ -316,6 +319,8 @@ private[emitter] final class SJSGen(
316319 case NoType | NullType | NothingType | _:RecordType =>
317320 throw new AssertionError (s " Unexpected type $tpe in genAsInstanceOf " )
318321 }
322+
323+ wg(resultTree)
319324 }
320325 }
321326
0 commit comments