Skip to content

Scala.js: Fix 3 codegen bugs to enable RegressionTest.scala. #9630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1838,13 +1838,17 @@ class JSCodeGen()(using genCtx: Context) {
* **which includes when either is a JS type**.
* When it is statically known that both sides are equal and subtypes of
* Number or Character, not using the rich equality is possible (their
* own equals method will do ok.)
* own equals method will do ok), except for java.lang.Float and
* java.lang.Double: their `equals` have different behavior around `NaN`
* and `-0.0`, see Javadoc (scala-dev#329, scala-js#2799).
*/
val mustUseAnyComparator: Boolean = {
isJSType(lsym) || isJSType(rsym) || {
val p = ctx.platform
val areSameFinals = lsym.is(Final) && rsym.is(Final) && (ltpe =:= rtpe)
!areSameFinals && p.isMaybeBoxed(lsym) && p.isMaybeBoxed(rsym)
p.isMaybeBoxed(lsym) && p.isMaybeBoxed(rsym) && {
val areSameFinals = lsym.is(Final) && rsym.is(Final) && (ltpe =:= rtpe)
!areSameFinals || lsym == defn.BoxedFloatClass || lsym == defn.BoxedDoubleClass
}
}
}

Expand Down Expand Up @@ -1976,10 +1980,11 @@ class JSCodeGen()(using genCtx: Context) {
genArg
case _ =>
implicit val pos = tree.span
/* TODO Check for a null receiver?
* In theory, it's UB, but that decision should be left for link time.
*/
js.Block(genReceiver, genArg)
js.Block(
js.If(js.BinaryOp(js.BinaryOp.===, genReceiver, js.Null()),
js.Throw(js.New(NullPointerExceptionClass, js.MethodIdent(jsNames.NoArgConstructorName), Nil)),
js.Skip())(jstpe.NoType),
genArg)
}
}

Expand Down Expand Up @@ -2277,9 +2282,11 @@ class JSCodeGen()(using genCtx: Context) {
abortMatch(s"Invalid selector type ${genSelector.tpe}")
}

val resultType =
if (isStat) jstpe.NoType
else toIRType(tree.tpe)
val resultType = toIRType(tree.tpe) match {
case jstpe.NothingType => jstpe.NothingType // must take priority over NoType below
case _ if isStat => jstpe.NoType
case resType => resType
}

var clauses: List[(List[js.Tree], js.Tree)] = Nil
var optDefaultClause: Option[js.Tree] = None
Expand Down Expand Up @@ -3470,6 +3477,7 @@ class JSCodeGen()(using genCtx: Context) {

object JSCodeGen {

private val NullPointerExceptionClass = ClassName("java.lang.NullPointerException")
private val JSObjectClassName = ClassName("scala.scalajs.js.Object")

private val newSimpleMethodName = SimpleMethodName("new")
Expand Down
1 change: 0 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ object Build {
val dir = fetchScalaJSSource.value / "test-suite"
(
(dir / "shared/src/test/scala" ** (("*.scala": FileFilter)
-- "RegressionTest.scala" // IR checking errors
-- "ReflectiveCallTest.scala" // uses many forms of structural calls that are not allowed in Scala 3 anymore
-- "EnumerationTest.scala" // scala.Enumeration support for Scala.js is not implemented in dotc (yet)
-- "SymbolTest.scala" // uses the old literal symbol syntax, pending update upstream
Expand Down