DelayedInit bug that could affect Around/Before scopes

26 views
Skip to first unread message

James Roper

unread,
Oct 5, 2012, 10:34:04 PM10/5/12
to specs2...@googlegroups.com
Just a heads up to people about a Scala bug (at least in 2.9.2) that might affect you if you're using Around/Before scopes with named arguments.  Here's the bug:


Here's an example scope that could cause a problem:

abstract class MyAround(a: Int = 1, b: Int = 2) extends Around with Scope {
  def around[T](t: => T)(implicit evidence: (T) => Result) = {
    // do some init with a and b
    t
    // tear down
  }
}

And some code that would be broken by this:

"something" in new MyAround(b = 3) {
  // At this point, the around won't have been run
}

The work around is to always supply the arguments to the around in the order they are defined, which means you can't miss any, so in the above example I would always have to supply a value for a if I wanted to supply a value for b.

etorreborre

unread,
Oct 5, 2012, 10:48:11 PM10/5/12
to specs2...@googlegroups.com
Thanks James for the heads-up I never met that issue before.

Eric.
Reply all
Reply to author
Forward
0 new messages