Skip to content

Commit 12285ab

Browse files
authored
Merge pull request scala-js#4633 from sjrd/fix-optimized-strict-floats
Fix scala-js#4632: Fix strict-floats + optimized semantics.
2 parents 5e5880a + 0ae15d3 commit 12285ab

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/FunctionEmitter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
25972597
genIsInstanceOf(transformExprNoChar(expr), testType)
25982598

25992599
case AsInstanceOf(expr, tpe) =>
2600-
genAsInstanceOf(transformExprNoChar(expr), tpe)
2600+
extractWithGlobals(genAsInstanceOf(transformExprNoChar(expr), tpe))
26012601

26022602
case GetClass(expr) =>
26032603
genCallHelper("objectGetClass", transformExprNoChar(expr))

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/SJSGen.scala

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)