-
Notifications
You must be signed in to change notification settings - Fork 21
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
java.lang.InternalError: Malformed class name #5425
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5425?orig=1 |
@xeno-by said: public String getSimpleName() {
if (isArray())
return getComponentType().getSimpleName()+"[]";
String simpleName = getSimpleBinaryName();
if (simpleName == null) { // top level class
simpleName = getName();
return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
}
// According to JLS3 "Binary Compatibility" (13.1) the binary
// name of non-package classes (not top level) is the binary
// name of the immediately enclosing class followed by a '$' followed by:
// (for nested and inner classes): the simple name.
// (for local classes): 1 or more digits followed by the simple name.
// (for anonymous classes): 1 or more digits.
// Since getSimpleBinaryName() will strip the binary name of
// the immediatly enclosing class, we are now looking at a
// string that matches the regular expression "\$[0-9]*"
// followed by a simple name (considering the simple of an
// anonymous class to be the empty string).
// Remove leading "\$[0-9]*" from the name
int length = simpleName.length();
if (length < 1 || simpleName.charAt(0) != '$')
throw new InternalError("Malformed class name");
int index = 1;
while (index < length && isAsciiDigit(simpleName.charAt(index)))
index++;
// Eventually, this is the empty string iff this is an anonymous class
return simpleName.substring(index);
} classOf[A].getEnclosingClass().getName => "Test$" Well, according to the source code of getSimpleName, A should be flattened into Test$$A$1. What's even more interesting, the correct name indeed appears after LambdaLift, but then gets messed by Flatten: C:\Projects\Kepler\sandbox>scalac -Xprint:lambdalift,flatten t5425.scala
[[syntax trees at end of lambdalift]]// Scala source: t5425.scala
package <empty> {
final object Test extends Object with App with ScalaObject {
def <init>(): object Test = {
Test.super.<init>();
Test.this.$asInstanceOf[App$class]()./*App$class*/$init$();
()
};
{
scala.this.Predef.println(classOf[Test$$A$1].getSimpleName())
};
class A$1 extends Object with ScalaObject {
def <init>(): Test#A$1 = {
A$1.super.<init>();
()
}
}
}
}
[[syntax trees at end of flatten]]// Scala source: t5256c.scala
package <empty> {
final object Test extends Object with App with ScalaObject {
def <init>(): object Test = {
Test.super.<init>();
Test.this.$asInstanceOf[App$class]()./*App$class*/$init$();
Test.this.delayedInit(new Test$delayedInit$body(Test.this));
()
}
};
class Test$A$1 extends Object with ScalaObject {
def <init>(): Test$A$1 = {
Test$A$1.super.<init>();
()
}
};
final <synthetic> class Test$delayedInit$body extends scala.runtime.AbstractFunction0 with ScalaObject {
final def apply(): Object = {
{
scala.this.Predef.println(classOf[Test$A$1].getSimpleName())
};
scala.runtime.BoxedUnit.UNIT
};
def <init>($outer: object Test): Test$delayedInit$body = {
Test$delayedInit$body.super.<init>();
()
}
}
} |
@gkossakowski said: object Test extends App {
class A
println(classOf[A].getSimpleName())
} But this fails: object Test extends App {
object A {
class B
}
println(classOf[A.B].getSimpleName()) for the same reason as Eugene stated. The first example works because we put A into 'Test' class and not 'Test$'. Note that class without dollar sign is generated only for top-level objects as a place where we can put static forwarders to object's method. |
@paulp said: https://issues.scala-lang.org/secure/IssueNavigator.jspa?mode=hide&requestId=11004 |
@paulp said: |
@gkossakowski said: And we would keep the sun shining on this one: https://scala-webapps.epfl.ch/jenkins/view/Misc/job/scala-signatures/ It verifies problems mentioned in original thread do not come back. |
…t compile time. (milessabin#707) Doesn't change behavior at all (other than that nested types which previously triggered scala/bug#5425 now are printed like everything else), but does plausibly increase efficiency slightly when large numbers of calls to `.describe` are being made.
…t compile time. Doesn't change behavior at all (other than that nested types which previously triggered scala/bug#5425 now are printed like everything else), but does plausibly increase efficiency slightly when large numbers of calls to `.describe` are being made. Fixes milessabin#707.
The text was updated successfully, but these errors were encountered: