Skip to content

Commit

Permalink
Fix #3888: Always identify impl classes by their IMPLCLASS flag.
Browse files Browse the repository at this point in the history
Before, we sometimes used name-based identification of impl
classes. This was introduced in
ac54f18, before Scala.js 0.1! At
the time, we were still using a custom `Global` subtrait instead of
a compiler plugin, and a custom `.jstype` file reader instead of
the normal class-file reader of scalac. The flag was not present in
some cases of separate compilation. Now that we use a normal
compiler plugin, this issue does not seem to manifest itself
anymore. It seems this code was left there for 6 years for nothing.
  • Loading branch information
sjrd committed Nov 28, 2019
1 parent 6dbc8be commit 36a92e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -1514,7 +1514,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
mutatedLocalVars := mutable.Set.empty
) {
def isTraitImplForwarder = dd.rhs match {
case app: Apply => foreignIsImplClass(app.symbol.owner)
case app: Apply => isImplClass(app.symbol.owner)
case _ => false
}

Expand Down Expand Up @@ -2724,7 +2724,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
genPrimitiveJSCall(tree, isStat)
else
genApplyJSClassMethod(genExpr(receiver), sym, genActualArgs(sym, args))
} else if (foreignIsImplClass(sym.owner)) {
} else if (isImplClass(sym.owner)) {
genTraitImplApply(sym, args map genExpr)
} else if (sym.isClassConstructor) {
/* See #66: we have to emit a statically linked call to avoid calling a
Expand Down
Expand Up @@ -222,9 +222,6 @@ trait JSEncoding[G <: Global with Singleton] extends SubComponent {
js.Ident(localSymbolName(sym), Some(sym.unexpandedName.decoded))
}

def foreignIsImplClass(sym: Symbol): Boolean =
sym.isModuleClass && nme.isImplClassName(sym.name)

def encodeClassType(sym: Symbol): jstpe.Type = {
if (sym == definitions.ObjectClass) jstpe.AnyType
else if (isRawJSType(sym.toTypeConstructor)) jstpe.AnyType
Expand All @@ -245,7 +242,7 @@ trait JSEncoding[G <: Global with Singleton] extends SubComponent {
}

def needsModuleClassSuffix(sym: Symbol): Boolean =
sym.isModuleClass && !foreignIsImplClass(sym)
sym.isModuleClass && !isImplClass(sym)

def encodeComputedNameIdentity(sym: Symbol): String = {
assert(sym.owner.isModuleClass, sym)
Expand Down
Expand Up @@ -784,6 +784,10 @@ class RegressionTest {
assertEquals('a', d)
}

@Test def nested_object_named_class_issue_3888(): Unit = {
assertEquals(6, `class`.foo(5))
}

}

object RegressionTest {
Expand Down Expand Up @@ -842,4 +846,8 @@ object RegressionTest {
def overloaded(x: Any): Unit =
fail("Bug3281.overloaded(x: Any) was called")
}

object `class` { // scalastyle:ignore
def foo(x: Int): Int = x + 1
}
}

0 comments on commit 36a92e3

Please sign in to comment.