Aladdin - Scala Bugtracking
[#1077] project: compiler priority: low category: bug
submitter assigned to status date submitted
Nikolay Iulian fixed 2007-05-01 12:49:29.0
subject [contrib #451] scalac: Can't convert from UNIT to REFERENCE
code
I tried to boil this code down even more, but I'm unable to.
Making it simplier has scalac to compile the code just fine.

import java.lang.StringBuilder

class SVNManager
{
}

class ObjectPool[T](ref : T)
{
}

class A(opaque_bytes : Array[Byte], parent_a : A)
{
}

class B private ()
{
  private var path_elements : Array[String] = null

  private def this(new_svn : ObjectPool[SVNManager],
                   path_info : Pair[String,Array[String]]) = {
    this()
    path_elements = path_info._2
    // Uncomming this will generate a different error
    // svn = new_svn
  }

  def this(new_svn : ObjectPool[SVNManager],
           new_path : String) = {
    this(new_svn, (new_path, new_path.split("/")))
  }

  private var svn : ObjectPool[SVNManager] = null
  private var parent_folder_id_opt : Option[A] = null

  def asInstanceOfA() : A = {
    parent_folder_id_opt = parent_folder_id_opt.orElse {
      val parent_path_elements =
        path_elements.slice(0, path_elements.length - 1)
      val parent_path = parent_path_elements.deepMkString("/", "/", "")
      val parent_path_info = (parent_path, parent_path_elements)
      val parent_exploded_folder_id = new B(svn, parent_path_info)
      if (0 == parent_path_elements.length) {
        None
      }
      else {
        Some(parent_exploded_folder_id.asInstanceOfA())
      }
    }

    // Get an opaque bytestring for this.
    val opaque_bytes =
      new StringBuilder(path_elements.length.toString()).toString()
                                                        .getBytes("UTF-8")
    new A(opaque_bytes, parent_folder_id_opt.get)
  }
}


what happened
This generates



Exception in thread "main" java.lang.AssertionError: assertion failed: Can't convert from UNIT to REFERENCE(B)B.\
this.B$$path_elements_=(if (path_info._2().$isInstanceOf[scala.runtime.BoxedArray]())
  scala.runtime.ScalaRunTime.arrayValue(path_info._2().$asInstanceOf[scala.runtime.BoxedArray](), B.this.class$M\
ethod0())
else
  path_info._2().$asInstanceOf[scala.Array[java.lang.String]]()) at: s6.scala22:19
        at scala.Predef$.assert(Predef.scala:89)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.adapt(GenICode.scala:975)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:961)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:883)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:113)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
        at scala.List.foreach(List.scala:702)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:135)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:90)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
        at scala.List.foreach(List.scala:702)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:82)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:66)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:62)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:231)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)        at scala.tools.nsc.Globa\
l$GlobalPhase$$anonfun$2.apply(Global.scala:220)        at scala.Iterator$class.foreach(Iterator.scala:380)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:245)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:220)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:55)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
        at scala.tools.nsc.Global$Run.compile(Global.scala:562)
        at scala.tools.nsc.Main$.process(Main.scala:57)
        at scala.tools.nsc.Main$.main(Main.scala:79)
        at scala.tools.nsc.Main.main(Main.scala)


A couple of things I noticed.

1) If you remove the private from the first "def this", then it
   compiles fine.

2) The real code generates a different message.  I can't release this
   code though:

   [scalac] java.lang.AssertionError: assertion failed: I produce UNIT in a context where REFERENCE(ExplodedFold\
erId) is expected!
   [scalac]     at scala.Predef$.assert(Predef.scala:89)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICod\
ePhase$$genLoad(GenICode.scala:448)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICod\
ePhase$$genLoad(GenICode.scala:883)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:113)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
   [scalac]     at scala.List.foreach(List.scala:702)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:135)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:90)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
   [scalac]     at scala.List.foreach(List.scala:702)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:82)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
   [scalac]     at scala.List.foreach(List.scala:702)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:82)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
   [scalac]     at scala.List.foreach(List.scala:702)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:82)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:71)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:70)
   [scalac]     at scala.List.foreach(List.scala:702)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:70)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:82)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:66)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:62)
   [scalac]     at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:231)
   [scalac]     at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
   [scalac]     at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
   [scalac]     at scala.Iterator$class.foreach(Iterator.scala:380)
   [scalac]     at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:245)
   [scalac]     at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:220)
   [scalac]     at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:55)
   [scalac]     at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
   [scalac]     at scala.tools.nsc.Global$Run.compile(Global.scala:562)
   [scalac]     at scala.tools.ant.Scalac.execute(Scalac.scala:628)
   [scalac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   [scalac]     at org.apache.tools.ant.Task.perform(Task.java:364)
   [scalac]     at org.apache.tools.ant.Target.execute(Target.java:341)
   [scalac]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
   [scalac]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   [scalac]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)   [scalac]     at org.apache.to\
ols.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   [scalac]     at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   [scalac]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
   [scalac]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
   [scalac]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
   [scalac]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

Regards,
Blair
what expected no crash
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-05-01 12:55:34.0
contribution #451
Iulian  edited on  2007-05-01 14:16:21.0
Fixed it by not mangling names of private constructors, since the JVM treats in a special way (and the backend as well).