scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Cannot get symbol for trait's implementation class #5176

Closed scabug closed 12 years ago

scabug commented 12 years ago

This code says it all:


/** 
 * Tries to load a symbol for the `Foo$class` using Scala reflection.  
 * Since trait implementation classes do not get pickling information
 * symbol for them should be created using fallback mechanism
 * that exposes Java reflection information dressed up in
 * a Scala symbol.
 **/
object Test extends App {
  import scala.reflect.mirror
  val name = manifest[Foo].erasure.getName + "$class"
  val implClass = Class.forName(name)
  val symbol = mirror.classToSymbol(implClass)
  assert(symbol != mirror.NoSymbol)
}

trait Foo {
  def bar = 1
}

It fails at the moment for mysterious reason. Trying to investigate it.

scabug commented 12 years ago

Imported From: https://issues.scala-lang.org/browse/SI-5176?orig=1 Reporter: @gkossakowski

scabug commented 12 years ago

Commit Message Bot (anonymous) said: (grek in r25982) Allow to load $class classes using Scala reflection.

Tweaked implementation of invalidClassName method to exclude *$class clasess from the set of invalid names. It's not exactly clear what was the intent of this method in first place so I'm not sure if it's the best way to fix #5176. Added test-case that covers this issue.

Fixes #5176. Review by odersky.