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

forAll are now correctly translated also in their returning type, before it...

forAll are now correctly translated also in their returning type, before it was Unit (wrong), now it is always a boolean.
parent 1c96089d
Branches
Tags
No related merge requests found
...@@ -21,19 +21,13 @@ trait ForAllTransformer extends TypingTransformers ...@@ -21,19 +21,13 @@ trait ForAllTransformer extends TypingTransformers
class ForAllTransformer(unit: CompilationUnit) class ForAllTransformer(unit: CompilationUnit)
extends TypingTransformer(unit) extends TypingTransformer(unit)
{ {
override def transform(tree: Tree): Tree = { override def transform(tree: Tree): Tree = {
curTree = tree curTree = tree
tree match { tree match {
// case Apply(lhs @ Select(_, implyMethod), rhs) => case Apply(TypeApply(s: Select, _), rhs @ List(f @ Function(vparams,body))) if isSelectOfSpecsMethod(s.symbol, "forAll") =>
// println("info "+lhs.symbol.name.equals("==>"))
// if (lhs.symbol.tpe.decl("==>") != NoSymbol)
// println(">"+tree)
// else
// println(lhs.symbol + " and "+lhs.symbol.tpe)
// tree
case Apply(TypeApply(s: Select, _), rhs @ List(f @ Function(vparams,body))) if isForall(s) =>
atOwner(currentOwner) { atOwner(currentOwner) {
assert(vparams.size == 1, "funcheck.Specs.forAll properties are expected to take a single (tuple) parameter") assert(vparams.size == 1, "funcheck.Specs.forAll properties are expected to take a single (tuple) parameter")
...@@ -46,7 +40,7 @@ trait ForAllTransformer extends TypingTransformers ...@@ -46,7 +40,7 @@ trait ForAllTransformer extends TypingTransformers
f f
} else { } else {
// create a fresh name for each parameter declared parametric type // create a fresh name for each parameter declared parametric type
val freshNames = vtpes.map(i => fresh.newName("v")) val freshNames = vtpes.map(i => fresh.newName("v"))
val funSym = tree.symbol val funSym = tree.symbol
...@@ -111,14 +105,14 @@ trait ForAllTransformer extends TypingTransformers ...@@ -111,14 +105,14 @@ trait ForAllTransformer extends TypingTransformers
Apply(prop, buf.toList) Apply(prop, buf.toList)
} }
} }
localTyper.typed { localTyper.typed {
atPos(tree.pos) { atPos(tree.pos) {
ConsoleReporter.testStatsEx(Test.check(property)) //ConsoleReporter.testStatsEx(Test.check(property))
Test.isPassed(Test.check(property))
} }
} }
case t => case t =>
assert(false, "expected ValDef of type TypeRef, found "+t) assert(false, "expected ValDef of type TypeRef, found "+t)
...@@ -150,14 +144,10 @@ trait ForAllTransformer extends TypingTransformers ...@@ -150,14 +144,10 @@ trait ForAllTransformer extends TypingTransformers
param(argtype) param(argtype)
} }
private def isSelectOfSpecsMethod(s: Symbol, method: String): Boolean =
s == specsModule.tpe.decl(method)
private def isForall(s: Select): Boolean = {
val Select(selector,_) = s
selector.symbol == specsModule &&
s.symbol == specsModule.tpe.decl("forAll")
}
/** Quick (and dirty) hack for enabling tree substitution for pair elements. /** Quick (and dirty) hack for enabling tree substitution for pair elements.
* Specifically, this allow to map pair accesses such as p._1 to a new variable 'x' * Specifically, this allow to map pair accesses such as p._1 to a new variable 'x'
......
...@@ -776,5 +776,8 @@ trait ScalaCheck extends FreshNameCreator { ...@@ -776,5 +776,8 @@ trait ScalaCheck extends FreshNameCreator {
override protected lazy val moduleSym = definitions.getModule("org.scalacheck.Test") override protected lazy val moduleSym = definitions.getModule("org.scalacheck.Test")
def check(prop: Tree): Tree = moduleApply("check", prop) def check(prop: Tree): Tree = moduleApply("check", prop)
def isPassed(res: Tree): Tree = Select(res, "passed")
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment