Skip to content
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

Catch up with Scala 2.13.4 #4276

Merged
merged 3 commits into from
Nov 7, 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
14 changes: 10 additions & 4 deletions compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
(Nil, applyCtor)
case js.Block(prepStats :+ (applyCtor: js.ApplyStatic)) =>
(prepStats, applyCtor)
case _ =>
abort(s"Unexpected body for JS constructor dispatch resolution at ${body.pos}:\n$body")
}
val js.ApplyStatic(_, _, js.MethodIdent(ctorName), js.This() :: ctorArgs) =
applyCtor
Expand Down Expand Up @@ -1731,6 +1733,9 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
if method.name.isConstructor =>
method.name
}.get

case _ =>
abort(s"Unexpected secondary constructor body at ${tree.pos}:\n$tree")
}

val (primaryCtor :: Nil, secondaryCtors) = ctors.partition {
Expand Down Expand Up @@ -5207,13 +5212,14 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
s"wrong number of arguments for call to JS setter $sym at $pos")
genSelectSet(jsFunName, argsNoSpread.head)
} else if (jsInterop.isJSBracketAccess(sym)) {
assert(argc == 1 || argc == 2,
s"@JSBracketAccess methods should have 1 or 2 non-varargs arguments")
argsNoSpread match {
case List(keyArg) =>
case keyArg :: Nil =>
genSelectGet(keyArg)
case List(keyArg, valueArg) =>
case keyArg :: valueArg :: Nil =>
genSelectSet(keyArg, valueArg)
case _ =>
throw new AssertionError(
s"@JSBracketAccess methods should have 1 or 2 non-varargs arguments at $pos")
}
} else if (jsInterop.isJSBracketCall(sym)) {
val (methodName, actualArgs) = extractFirstArg(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ abstract class PrepJSInterop[G <: Global with Singleton](val global: G)

checkJSNameAnnots(sym)

val transformedTree: Tree = tree match {
// @unchecked needed because MemberDef is not marked `sealed`
val transformedTree: Tree = (tree: @unchecked) match {
case tree: ImplDef =>
if (shouldPrepareExports)
registerClassOrModuleExports(sym)
Expand Down Expand Up @@ -828,6 +829,9 @@ abstract class PrepJSInterop[G <: Global with Singleton](val global: G)
}
Some(loadSpec)

case Some(annot) =>
abort(s"checkAndGetJSNativeLoadingSpecAnnotOf returned unexpected annotation $annot")

case None =>
/* We already emitted an error. Invent something not to cause
* cascading errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MatchASTTest extends JSASTTest {
def stripIdentityMatchEndNonUnitResult: Unit = {
"""
object A {
def foo = "a" match {
def aString: String = "a"
def foo = aString match {
case "a" => true
case "b" => false
}
Expand All @@ -39,7 +40,8 @@ class MatchASTTest extends JSASTTest {
def stripIdentityMatchEndUnitResult: Unit = {
"""
object A {
def foo = "a" match {
def aString: String = "a"
def foo = aString match {
case "a" =>
case "b" =>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
}

case Assign(select @ ArraySelect(array, index), rhs) =>
unnest(List(array, index, rhs)) {
case (List(newArray, newIndex, newRhs), env0) =>
unnest(array, index, rhs) { (newArray, newIndex, newRhs, env0) =>
implicit val env = env0
val genArray = transformExprNoChar(newArray)
val genIndex = transformExprNoChar(newIndex)
Expand Down Expand Up @@ -616,8 +615,8 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
}

case Assign(select @ JSSelect(qualifier, item), rhs) =>
unnest(List(qualifier, item, rhs)) {
case (List(newQualifier, newItem, newRhs), env0) =>
unnest(qualifier, item, rhs) {
(newQualifier, newItem, newRhs, env0) =>
implicit val env = env0
js.Assign(
genBracketSelect(transformExprNoChar(newQualifier),
Expand All @@ -626,8 +625,8 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
}

case Assign(select @ JSSuperSelect(superClass, qualifier, item), rhs) =>
unnest(List(superClass, qualifier, item, rhs)) {
case (List(newSuperClass, newQualifier, newItem, newRhs), env0) =>
unnest(superClass, qualifier, item, rhs) {
(newSuperClass, newQualifier, newItem, newRhs, env0) =>
implicit val env = env0
genCallHelper("superSet", transformExprNoChar(newSuperClass),
transformExprNoChar(newQualifier), transformExprNoChar(item),
Expand Down Expand Up @@ -1070,17 +1069,39 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
/** Same as above, for a single argument */
def unnest(arg: Tree)(makeStat: (Tree, Env) => js.Tree)(
implicit env: Env): js.Tree = {
unnest(List(arg)) {
case (List(newArg), env) => makeStat(newArg, env)
unnest(List(arg)) { (newArgs, env) =>
val newArg :: Nil = newArgs
makeStat(newArg, env)
}
}

/** Same as above, for two arguments */
def unnest(lhs: Tree, rhs: Tree)(
def unnest(arg1: Tree, arg2: Tree)(
makeStat: (Tree, Tree, Env) => js.Tree)(
implicit env: Env): js.Tree = {
unnest(List(lhs, rhs)) {
case (List(newLhs, newRhs), env) => makeStat(newLhs, newRhs, env)
unnest(List(arg1, arg2)) { (newArgs, env) =>
val newArg1 :: newArg2 :: Nil = newArgs
makeStat(newArg1, newArg2, env)
}
}

/** Same as above, for 3 arguments */
def unnest(arg1: Tree, arg2: Tree, arg3: Tree)(
makeStat: (Tree, Tree, Tree, Env) => js.Tree)(
implicit env: Env): js.Tree = {
unnest(List(arg1, arg2, arg3)) { (newArgs, env) =>
val newArg1 :: newArg2 :: newArg3 :: Nil = newArgs
makeStat(newArg1, newArg2, newArg3, env)
}
}

/** Same as above, for 4 arguments */
def unnest(arg1: Tree, arg2: Tree, arg3: Tree, arg4: Tree)(
makeStat: (Tree, Tree, Tree, Tree, Env) => js.Tree)(
implicit env: Env): js.Tree = {
unnest(List(arg1, arg2, arg3, arg4)) { (newArgs, env) =>
val newArg1 :: newArg2 :: newArg3 :: newArg4 :: Nil = newArgs
makeStat(newArg1, newArg2, newArg3, newArg4, env)
}
}

Expand Down Expand Up @@ -1702,8 +1723,8 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
}

case JSSuperSelect(superClass, qualifier, item) =>
unnest(List(superClass, qualifier, item)) {
case (List(newSuperClass, newQualifier, newItem), env) =>
unnest(superClass, qualifier, item) {
(newSuperClass, newQualifier, newItem, env) =>
redo(JSSuperSelect(newSuperClass, newQualifier, newItem))(env)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class RegressionTest {
}

@Test def should_correctly_call_subSequence_on_non_string_CharSequences_issue_55(): Unit = {
val arr: CharSequence = Array('a','b','c','d')
val ss = arr.subSequence(2,3)
val arr: CharSequence = java.nio.CharBuffer.wrap(Array('a', 'b', 'c', 'd'))
val ss = arr.subSequence(2, 3)
assertEquals(1, ss.length())
assertEquals('c', ss.charAt(0))
}
Expand Down