Skip to content
Snippets Groups Projects
Commit 41e3cdff authored by Mirco Dotta's avatar Mirco Dotta
Browse files

Generators are now created lazily to avoid filling the stack because of...

Generators are now created lazily to avoid filling the stack because of recrursive calls in the injected Generator methods
parent 651ee9f8
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ trait ForAllTransformer extends TypingTransformers
case tpe @ TypeRef(_,_,ptpes) =>
vtpt.tpe match {
case TypeRef(_,value,vtpes) =>
val fun: Function = {
var fun: Function = {
if(vtpes.size <= 1) {
f
} else {
......
......@@ -61,6 +61,8 @@ trait ScalaCheck extends FreshNameCreator {
def oneOf(generators: List[Symbol]): Tree =
Apply(Select(Ident(moduleGenSym), symDecl(moduleGenSym, "oneOf")), generators.map(Ident(_)))
def lzy(generator: Tree): Tree =
Apply(Select(Ident(moduleGenSym), symDecl(moduleGenSym, "lzy")), List(generator))
/**
* This creates a Tree node for the call <code>org.scalacheck.Gen.flatMap[T](body)</code>,
......@@ -81,6 +83,8 @@ trait ScalaCheck extends FreshNameCreator {
def map(qualifier: Tree, body: Tree): Tree =
Apply(Select(qualifier, symDecl(classGenSym, "map")), List(body))
/**
* Utilitary method for creating a method symbol for a <code>org.scalacheck.Gen</codee>
* generator method.
......@@ -191,7 +195,7 @@ trait ScalaCheck extends FreshNameCreator {
if(cd.symbol.hasFlag(scala.tools.nsc.symtab.Flags.ABSTRACT)) {
val generators = retTpe.symbol.children.toList.map(s => genSymbolsForType(s.tpe)).flatMap(v=>v)
DefDef(genDef, Modifiers(0), List(), Gen.oneOf(generators))
DefDef(genDef, Modifiers(0), List(), Gen.lzy(Gen.oneOf(generators)))
}
else {
......@@ -242,7 +246,7 @@ trait ScalaCheck extends FreshNameCreator {
}
}
body
Gen.lzy(body)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment