Aladdin - Scala Bugtracking
[#967] project: compiler priority: low category: bug
submitter assigned to status date submitted
Nikolay Martin noise 2007-02-26 16:01:15.0
subject [contrib #353] valid method call yields compiler error message
code
object Foo
{
  private val all = new scala.collection.mutable.HashSet[Foo]

  def add(foo: Foo) =
  {
    all += foo
    allSorted()
    1
  }

  def allSorted() = all.toList.sort((a, b) => a.id < b.id)

}

abstract class Foo
{
  val id = Foo.add(this)
}
what happened
scala and fsc 2.3.3 give error message ("recursive method add needs result type"), unless call to allSorted() is\
 removed
what expected clean compilation
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-02-26 16:02:48.0
contribution #353. I shortened the code a bit
Martin  edited on  2007-02-27 23:30:05.0
The error message is correct: the type of add depends on allsorted which depends on the type of Foo.id, which depends on add.
Nikolay  edited on  2007-02-28 10:46:39.0
My bad. I cut the contribution example too much. I now added a 1 at the end of add so the inferred type should not depend on allSorted
Nikolay  edited on  2007-02-28 12:26:39.0
Apparently, it doesn't matter if allSorted is last or not. Its type is still required for the typechecking of the body of add.