Skip to content

Commit

Permalink
Fixes #290 (deadlock under 2.12 during property initialization)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4dd1a15)
  • Loading branch information
mpilquist authored and rickynils committed Nov 1, 2016
1 parent 4aff739 commit c80c840
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
@@ -0,0 +1,26 @@
/*-------------------------------------------------------------------------*\
** ScalaCheck **
** Copyright (c) 2007-2016 Rickard Nilsson. All rights reserved. **
** http://www.scalacheck.org **
** **
** This software is released under the terms of the Revised BSD License. **
** There is NO WARRANTY. See the file LICENSE for the full text. **
\*------------------------------------------------------------------------ */

package org.scalacheck

object LazyPropertiesSpecification extends Properties("Properties.lazy registration") {

property("properties registered lazily") = {
var evaluated = false
val p = new Properties("P") {
property("p") = {
evaluated = true
Prop.proved
}
}
evaluated == false
}

}

3 changes: 3 additions & 0 deletions src/main/scala/org/scalacheck/Prop.scala
Expand Up @@ -301,6 +301,9 @@ object Prop {
/** Create a property from a boolean value */
def apply(b: Boolean): Prop = if(b) proved else falsified

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


// Implicits

Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/org/scalacheck/Properties.scala
Expand Up @@ -84,7 +84,13 @@ class Properties(val name: String) extends Prop {
* }}}
*/
class PropertySpecifier() {
def update(propName: String, p: Prop) = props += ((name+"."+propName, p))
// TODO: Delete this in 1.14 -- kept for binary compat with 1.13.3 and prior
protected def update(propName: String, p: Prop) = {
props += ((name+"."+propName, p))
}
def update(propName: String, p: => Prop) = {
props += ((name+"."+propName, Prop.suspend(p)))
}
}

lazy val property = new PropertySpecifier()
Expand Down

0 comments on commit c80c840

Please sign in to comment.