Skip to content

Commit c80c840

Browse files
mpilquistrickynils
authored andcommitted
Fixes #290 (deadlock under 2.12 during property initialization)
(cherry picked from commit 4dd1a15)
1 parent 4aff739 commit c80c840

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*-------------------------------------------------------------------------*\
2+
** ScalaCheck **
3+
** Copyright (c) 2007-2016 Rickard Nilsson. All rights reserved. **
4+
** http://www.scalacheck.org **
5+
** **
6+
** This software is released under the terms of the Revised BSD License. **
7+
** There is NO WARRANTY. See the file LICENSE for the full text. **
8+
\*------------------------------------------------------------------------ */
9+
10+
package org.scalacheck
11+
12+
object LazyPropertiesSpecification extends Properties("Properties.lazy registration") {
13+
14+
property("properties registered lazily") = {
15+
var evaluated = false
16+
val p = new Properties("P") {
17+
property("p") = {
18+
evaluated = true
19+
Prop.proved
20+
}
21+
}
22+
evaluated == false
23+
}
24+
25+
}
26+

src/main/scala/org/scalacheck/Prop.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ object Prop {
301301
/** Create a property from a boolean value */
302302
def apply(b: Boolean): Prop = if(b) proved else falsified
303303

304+
/** Create a prop that evaluates the by-name argument on each application. */
305+
def suspend(p: => Prop): Prop = apply(prms => p(prms))
306+
304307

305308
// Implicits
306309

src/main/scala/org/scalacheck/Properties.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ class Properties(val name: String) extends Prop {
8484
* }}}
8585
*/
8686
class PropertySpecifier() {
87-
def update(propName: String, p: Prop) = props += ((name+"."+propName, p))
87+
// TODO: Delete this in 1.14 -- kept for binary compat with 1.13.3 and prior
88+
protected def update(propName: String, p: Prop) = {
89+
props += ((name+"."+propName, p))
90+
}
91+
def update(propName: String, p: => Prop) = {
92+
props += ((name+"."+propName, Prop.suspend(p)))
93+
}
8894
}
8995

9096
lazy val property = new PropertySpecifier()

0 commit comments

Comments
 (0)