Bug/typo in continuations/ControlContext.scala?

117 views
Skip to first unread message

Simon Ochsenreither

unread,
Aug 16, 2013, 6:46:07 AM8/16/13
to scala-i...@googlegroups.com
Sorry if I'm missing something, but this looked too suspicious to not raise a question why it is done ...

During cleaning up -feature/-Xlint/etc. warnings I saw this item:

[quick.plugins] /home/soc/Entwicklung/scala/src/continuations/library/scala/util/continuations/ControlContext.scala:233: warning: local val in value $anonfun is never used
[quick.plugins]         val thr: Exception => B = { t: Exception =>
[quick.plugins]             ^

The code looks like this: https://github.com/scala/scala/blob/master/src/continuations/library/scala/util/continuations/ControlContext.scala#L212

It almost feels like the returning result should read
fun(ret, thr)
instead of
fun(ret, thr1)
so that the local val thr is used. Otherwise, what's the reason to give it a name?

Any insights?




Paolo G. Giarrusso

unread,
Aug 16, 2013, 9:56:36 PM8/16/13
to scala-i...@googlegroups.com
I can't be entirely sure, but I think you're right and it'd be a big deal if that code were used. However, currently that's dead code anyway:


(I also ran `grep mapFinally -r scala/src/`, finding no other usage).

I'd probably fix the bug you found, alternatively I'd remove mapFinally altogether since it's not tested.

What's happening is hard to explain, but I guess that if mapFinally were actually used, a finally at the right location, in an example like the following, would be skipped.

reset {
  try {
    f1(shift(k => throw new Exception))
  } catch {
    case e =>
  } finally { //I'm guessing this finally could be expressed with mapFinally, but currently mapFinally is not used.
    f2()
  }
}

In short, mapFinally would be used to add the call to `f2()` to a ControlContext, that is a representation of the local of shift in continuation-passing style. Because of this typo, f2 is however not called when the argument of shift throws an exception, defeating the point of using `finally`.

Simon Ochsenreither

unread,
Aug 18, 2013, 3:03:21 PM8/18/13
to scala-i...@googlegroups.com, philipp...@typesafe.com
Pinging Philipp Haller ...

Paolo G. Giarrusso

unread,
Aug 21, 2013, 9:57:40 PM8/21/13
to scala-i...@googlegroups.com, philipp...@typesafe.com
On Sunday, August 18, 2013 9:03:21 PM UTC+2, Simon Ochsenreither wrote:
Pinging Philipp Haller ...

Seems not going to work. The other discussion shows that this code is (essentially) unmaintained and might move to community maintenance:
https://groups.google.com/d/topic/scala-internals/9Ts3GLsXuOg/discussion 

[This email is brought to you thanks to the principle of communicating vessels.]
Reply all
Reply to author
Forward
0 new messages