Skip to content

Commit 800081e

Browse files
committed
Fix scala-js#1932: Recognize 2.12.0-M3's new shape of spurious classOf[T] trees.
The scala/scala PR scala/scala#4749 changed the shape of the spurious `Predef.classOf[T]` that reach the `jsinterop` phase. Previously they looked like `scala.this.Predef.classOf[T]`, where as now they are `scala.Predef.classOf[T]`. This commit generalizes the shapes of trees we recognize, so that both patterns are matched. (cherry picked from commit eefb50a)
1 parent 8a6148d commit 800081e

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

compiler/src/main/scala/org/scalajs/core/compiler/PrepJSInterop.scala

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,27 @@ abstract class PrepJSInterop extends plugins.PluginComponent
270270
EmptyTree
271271
}
272272

273-
// Catch calls to Predef.classOf[T]. These should NEVER reach this phase
274-
// but unfortunately do. In normal cases, the typer phase replaces these
275-
// calls by a literal constant of the given type. However, when we compile
276-
// the scala library itself and Predef.scala is in the sources, this does
277-
// not happen.
278-
//
279-
// The trees reach this phase under the form:
280-
//
281-
// scala.this.Predef.classOf[T]
282-
//
283-
// If we encounter such a tree, depending on the plugin options, we fail
284-
// here or silently fix those calls.
285-
case TypeApply(
286-
classOfTree @ Select(Select(This(jstpnme.scala_), nme.Predef), nme.classOf),
287-
List(tpeArg)) =>
273+
/* Catch calls to Predef.classOf[T]. These should NEVER reach this phase
274+
* but unfortunately do. In normal cases, the typer phase replaces these
275+
* calls by a literal constant of the given type. However, when we compile
276+
* the scala library itself and Predef.scala is in the sources, this does
277+
* not happen.
278+
*
279+
* The trees reach this phase under the form:
280+
*
281+
* scala.this.Predef.classOf[T]
282+
*
283+
* or, as of Scala 2.12.0-M3, as:
284+
*
285+
* scala.Predef.classOf[T]
286+
*
287+
* or so it seems, at least.
288+
*
289+
* If we encounter such a tree, depending on the plugin options, we fail
290+
* here or silently fix those calls.
291+
*/
292+
case TypeApply(classOfTree @ Select(predef, nme.classOf), List(tpeArg))
293+
if predef.symbol == PredefModule =>
288294
if (scalaJSOpts.fixClassOf) {
289295
// Replace call by literal constant containing type
290296
if (typer.checkClassType(tpeArg)) {

0 commit comments

Comments
 (0)