Re: sbt 0.12.2 and Scala 2.10 reflection

230 views
Skip to first unread message

Jeff Olson

unread,
Mar 7, 2013, 5:20:32 PM3/7/13
to simple-b...@googlegroups.com
Just a wild guess, but are you running your test serially or in parallel?


-Jeff

On Thursday, March 7, 2013 1:10:28 PM UTC-6, Jordi Pradel wrote:
Hello,

I'm trying to compile a project where I use Scala 2.10 reflection api for runtime reflection.

Everything is fine if I compile with my usual IDE (IntelliJ), but when I clean and run tests with sbt only, I get test failures that vary from execution to execution, like:
  • java.lang.AssertionError: assertion failed: no symbol could be loaded from interface java.util.Collection in package util with name Collection and classloader null
  • scala.reflect.internal.Types$TypeError: illegal cyclic inheritance involving trait Map
  • scala.reflect.internal.Types$TypeError: illegal cyclic inheritance involving trait Product
  • java.lang.AssertionError: assertion failed: not a type: symbol
I tried building the project with sbt-0.13 nightly build (last available today) and it works perfectly.

Is there any work around to build such a project with sbt 0.12? Or maybe it is supposed to work and I may be doing something wrong?

Just in case it may help, here I add a fragment of Scala code where the aforementioned exceptions are being thrown:

  def schemaOf[T](scalaType: Type) = scalaType match {
         case t if t =:= typeOf[Byte] => "integer"
      case t if t =:= typeOf[Short] => "integer"
      // More cases omitted for brevity
         case t if t <:< weakTypeOf[Option[_]] => "option " + schemaOf(t.asInstanceOf[TypeRefApi].args.head
      case t if t <:< typeOf[Map[String, Any]] => "map"
      case t if t <:< weakTypeOf[TraversableOnce[_]] => {
        "collection " + schemaOf(t.asInstanceOf[TypeRefApi].args.head
      }
         case _ => {
        val fields = scalaType.members.filter(s => s.isTerm && !s.isMethod)
        val name = scalaType.typeSymbol.name.toString
        "object " + name + " with fields " + fields
      }
    }





Thanks in advance,
Jordi


Jordi Pradel

unread,
Mar 10, 2013, 5:54:52 AM3/10/13
to simple-b...@googlegroups.com
Thanks, Jeff, you made my day!

I had two test sepcs using reflection and SBT was executing them both in parallel, a good recipe for disaster. In fact, the results being different on each execution should have pointed me to a parallelism issue, but I just didn't catch on.

Thanks!
Reply all
Reply to author
Forward
0 new messages