Skip to content

Commit eefb50a

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.
1 parent 8f3ed17 commit eefb50a

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
@@ -265,21 +265,27 @@ abstract class PrepJSInterop extends plugins.PluginComponent
265265
}
266266
}
267267

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

0 commit comments

Comments
 (0)