Skip to content

Commit

Permalink
Fix detection of "foreign" impl classes.
Browse files Browse the repository at this point in the history
Foreign impl classes are those loaded from .class files.
When they are loaded through their representative's
pickle, they receive the IMPLCLASS flag, and hence
sym.isImplClass is true. However, when they are loaded
through a $class.class file, they do not get the IMPLCLASS
flag, and sym.isImplClass returns false.

This does not really matter to scalac. But to Scala.js,
it matters because impl classes are encoded totally
differently from module classes.

So this commit fixes the issue by doing "true" detection
of impl classes through their name. This done only when
the class is not being compiled in the current compilation
unit, because in that case we now it does have the flag.
  • Loading branch information
sjrd committed Oct 3, 2013
1 parent 63a55de commit ac54f18
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -86,7 +86,7 @@ trait JSEncoding extends SubComponent { self: GenJSCode =>
require(sym.isMethod, "encodeMethodSym called with non-method symbol: " + sym)
val encodedName =
if (sym.isClassConstructor) "init" + InnerSep
else if (!sym.owner.isImplClass) sym.name.toString
else if (!foreignIsImplClass(sym.owner)) sym.name.toString
else encodeClassFullName(sym.owner) + OuterSep + sym.name.toString
val paramsString = makeParamsString(sym)
js.Ident(encodedName + paramsString,
Expand Down Expand Up @@ -130,13 +130,16 @@ trait JSEncoding extends SubComponent { self: GenJSCode =>
require(sym.isModuleClass,
"encodeModuleSym called with non-moduleClass symbol: " + sym)

if (sym.isImplClass)
if (foreignIsImplClass(sym))
envField("impls")
else
js.Apply(js.DotSelect(envField("modules"),
encodeModuleFullNameIdent(sym)), Nil)
}

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

def encodeIsInstanceOf(value: js.Tree, tpe: Type)(
implicit pos: Position): js.Tree = {
encodeIsAsInstanceOf("is")(value, tpe)
Expand Down Expand Up @@ -186,7 +189,7 @@ trait JSEncoding extends SubComponent { self: GenJSCode =>

def encodeClassFullName(sym: Symbol, separator: Char = InnerSep): String = {
val base = sym.fullNameAsName(separator).toString
if (sym.isModuleClass && !sym.isImplClass) base + "$" else base
if (sym.isModuleClass && !foreignIsImplClass(sym)) base + "$" else base
}

def encodeModuleFullName(sym: Symbol, separator: Char = InnerSep): String =
Expand Down

0 comments on commit ac54f18

Please sign in to comment.