Aladdin - Scala Bugtracking
[#505] project: nsc priority: low category: bug
submitter assigned to status date submitted
Sean _ _ 2005-12-02 19:23:54.0
subject code passes NSC typecheck, triggers assert during codegen
code
<pre>
class Test {
  def foo : String = "foo";
  def bar : Unit = foo;

  System.err.println(bar + " hello ");


}
</pre>
what happened
Compiled under NSC fails with:
Exception in thread "main" java.lang.Error: assertion failed: Can't convert from UNIT to REFERENCE(java.lang.Obj\
ect)Test.this.bar() at: Test.scala7:22
	at scala.Predef$.assert(Predef.scala:144)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ad\
apt(GenICode.scala:846)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoad(GenICode.scala:832)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoadQualifier(GenICode.scala:865)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoad(GenICode.scala:681)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoadArguments(GenICode.scala:911)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoad(GenICode.scala:685)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nStat(GenICode.scala:175)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ac\
cess$scala$tools$nsc$backend$icode$GenICode$ICodePhase$genStat(GenICode.scala:27)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$3.apply(GenICode.scala:138)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$3.apply(GenICode.scala:138)
	at scala.List$class.scala$List$loop$5(List.scala:577)
	at scala.List$class.foreach(List.scala:579)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nStat(GenICode.scala:138)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.scala$tools$nsc$backend$icode$GenICode$ICodePhase$ge\
nLoad(GenICode.scala:758)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:108)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$0.apply(GenICode.scala:62)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$0.apply(GenICode.scala:62)
	at scala.List$class.scala$List$loop$5(List.scala:577)
	at scala.List$class.foreach(List.scala:579)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:62)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:128)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:79)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$0.apply(GenICode.scala:62)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anon$0.apply(GenICode.scala:62)
	at scala.List$class.scala$List$loop$5(List.scala:577)
	at scala.List$class.foreach(List.scala:579)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:62)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:72)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.gen(GenICode.scala:57)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.apply(GenICode.scala:54)
	at scala.tools.nsc.Global$GlobalPhase$class.applyPhase(Global.scala:170)
	at scala.tools.nsc.Global$GlobalPhase$$anon$7.apply(Global.scala:162)
	at scala.tools.nsc.Global$GlobalPhase$$anon$7.apply(Global.scala:162)
	at scala.Iterator$class.foreach(Iterator.scala:262)
	at scala.tools.nsc.Global$GlobalPhase$class.run(Global.scala:162)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$class.run(GenICode.scala:48)
	at scala.tools.nsc.Global$Run$class.compileSources(Global.scala:344)
	at scala.tools.nsc.Global$Run$$anon$20.apply(Global.scala:402)
	at scala.tools.nsc.Global$Run$$anon$20.apply(Global.scala:402)
	at scala.runtime.ScalaRunTime$$anon$0.run(ScalaRunTime.scala:34)
	at scala.runtime.RunTime.tryCatch(RunTime.java:79)
	at scala.runtime.ScalaRunTime$$anon$0.(ScalaRunTime.scala:32)
	at scala.runtime.ScalaRunTime$.Try(ScalaRunTime.scala:30)
	at scala.tools.nsc.Global$Run$class.compile(Global.scala:401)
	at scala.tools.nsc.Main$$anon$4.apply(Main.scala:55)
	at scala.tools.nsc.Main$$anon$4.apply(Main.scala:48)
	at scala.runtime.ScalaRunTime$$anon$0.run(ScalaRunTime.scala:34)
	at scala.runtime.RunTime.tryCatch(RunTime.java:79)
	at scala.runtime.ScalaRunTime$$anon$0.(ScalaRunTime.scala:32)
	at scala.runtime.ScalaRunTime$.Try(ScalaRunTime.scala:30)
	at scala.tools.nsc.Main$.process(Main.scala:48)
	at scala.tools.nsc.Main$.main(Main.scala:67)
	at scala.tools.nsc.Main.main(Main.scala:66)
what expected Should fail during typecheck (defs of type unit should not be usable as strings).
[back to overview]
Changes of this bug report
Iulian  edited on  2005-12-02 20:06:32.0
The code should compile and run fine, because class scala.Unit has a method '+' which takes a String and returns a String. The problem is that a boxing operation is missing. Here's the code after erasure:
System.err.println(Test.this.bar().+(" hello "));
but it should be something like:
System.err.println({
  Test.this.bar();
  BoxedUnit.UNIT
}.+(" hello "));
Martin  edited on  2005-12-02 20:33:56.0
I tend to agree with Sean. What use is it to give a $plus method to Unit? This might only mask some errors, IMO. So I propose to remove $plus from Unit.java.
Iulian  edited on  2005-12-02 20:42:54.0
We could remove it, but then we should remove all '+' methods from value classes. It seems to me they served as shortcuts when concatenating strings. One could write 1 + " is greater than " + 2 or () + " is a unit" without having to write a dummy string before, as in Java. Since this does not work for reference types, I guess not that many people knew/used this feature.