Aladdin - Scala Bugtracking
[#552] project: compiler priority: low category: bug
submitter assigned to status date submitted
Lex Iulian fixed 2006-03-17 16:02:39.0
subject returning out of synchronized methods
code
object Test {
  def abs(x:int): int = synchronized {
    if(x > 0)
      return x
    return -x
  }

  def main(args: Array[String]) = {
    Console.println("abs(-5) = " + abs(-5))
  }
}
what happened
Exception in thread "main" java.lang.IllegalMonitorStateException
	at Test$.abs(retsynch.scala:5)
	at Test$.main(retsynch.scala:9)
	at Test.main(retsynch.scala)
what expected It should compile and run just fine.
[back to overview]
Changes of this bug report
Martin  edited on  2006-03-18 11:24:34.0
Actually, this is probably for me to fix. The problem is that the return is non-local, i.e. we try to return out of a nested closure from an enclosing function. Such non-local returns are not yet implemented. The old scalac contained a test and error message which seems to be missing in the new one. I'll see whether we do that for the moment, or whether we can implement non-local returns now (using exceptions). Cheers -- Martin
Martin  edited on  2006-03-18 11:37:45.0
Correction: Synchronized does not take a closure (it used to, but the present implementation is more efficient). So my discussion about non-local returns does not apply and this is for Iulian to fix, after all! -- Martin
Iulian  edited on  2006-03-20 12:50:16.0