| [#31] | project: compiler | priority: medium | category: bug | |
|---|---|---|---|---|
| submitter | assigned to | status | date submitted | |
| Stephane | Martin | fixed | 2003-06-05 18:26:50.0 | |
| subject | type mismatch error | |||
| code |
object Main {
trait Ensure[a] {
def ensure(postcondition: a => Boolean): a
}
def require[a](def precondition: Boolean)(def command: a): Ensure[a] =
if (precondition)
new Ensure[a] {
def ensure(postcondition: a => Boolean): a = {
val result = command;
if (postcondition(result)) result
else error("Assertion error")
}
}
else
error("Assertion error");
def arb[a](s: List[a]) =
require (! s.isEmpty) {
s.head
} ensure (result => s contains result);
def main(args: Array[String]) = {
val s = List(1, 2);
System.out.println(arb(s))
}
}
|
|||
| what happened | Main.scala:21: type mismatch;
found : a
required: scala.All
s.head
^
Main.scala:22: missing parameter type
} ensure (result => s contains result);
^
two errors found
|
|||
| what expected | value 1 is printed out. | |||
| [back to overview] | ||||