aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-21 16:00:20 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-21 16:01:35 +0100
commit9c609da1109b4f83622f4b7b527ef730e7a4d2d8 (patch)
treea08f59da6a3728196d9e10cbb455ed26f92ec1d7
parentbec521d2cfc22274213ac5066d8817a085faa316 (diff)
downloadPraspel-9c609da1109b4f83622f4b7b527ef730e7a4d2d8.zip
Praspel-9c609da1109b4f83622f4b7b527ef730e7a4d2d8.tar.gz
Praspel-9c609da1109b4f83622f4b7b527ef730e7a4d2d8.tar.bz2
Cannot have global/parent @ensures or @throwable.
The semantics of a global @throwable clause is really hard to define. Same for @ensures. After a study, we realized that users do not write global or parent @ensures or @throwable clauses. Thus, to simplify everything, we reject such contract constructions.
-rw-r--r--Model/Behavior.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/Model/Behavior.php b/Model/Behavior.php
index efa7c31..fdc12d1 100644
--- a/Model/Behavior.php
+++ b/Model/Behavior.php
@@ -171,10 +171,20 @@ class Behavior extends Clause {
break;
case 'ensures':
+ if(true === $this->clauseExists('behavior'))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Cannot add the @ensures clause, since a @behavior ' .
+ 'clause exists at the same level.', 1);
+
$handle = new Ensures($this);
break;
case 'throwable':
+ if(true === $this->clauseExists('behavior'))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Cannot add the @throwable clause, since a @behavior ' .
+ 'clause exists at the same level.', 2);
+
$handle = new Throwable($this);
break;
@@ -183,6 +193,12 @@ class Behavior extends Clause {
break;
case 'behavior':
+ if( true === $this->clauseExists('ensures')
+ || true === $this->clauseExists('throwable'))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Cannot add the @behavior clause, since an @ensures ' .
+ 'or a @throwable clause exists at the same level.', 3);
+
$handle = new Collection(
new self($this),
function ( self $clause, $identifier ) {
@@ -195,6 +211,12 @@ class Behavior extends Clause {
break;
case 'default':
+ if( true === $this->clauseExists('ensures')
+ || true === $this->clauseExists('throwable'))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Cannot add the @default clause, since an @ensures ' .
+ 'or a @throwable clause exists at the same level.', 4);
+
$handle = new DefaultBehavior($this);
break;