Pārlūkot izejas kodu

Removed test case of a "todo"-bug (bug turned out not to exist after all). Added test for checking whether guard conditions are expressions of boolean-type.

Joeri Exelmans 5 gadi atpakaļ
vecāks
revīzija
49149eb5b6

+ 1 - 1
src/sccd/statechart/dynamic/statechart_execution.py

@@ -79,7 +79,7 @@ class StatechartExecution:
                             self.history_values[history_id] = exit_ids & history_mask
                         if s.opt.shallow_history is not None:
                             history_id = s.opt.shallow_history
-                            self.history_values[history_id] = just_exited._effective_targets()
+                            self.history_values[history_id] = just_exited.opt.effective_targets
                         self._cancel_timers(s.opt.after_triggers)
                         _perform_actions(ctx, s.exit)
                         self.configuration &= ~s.opt.state_id_bitmap

+ 3 - 1
src/sccd/statechart/parser/xml.py

@@ -242,7 +242,9 @@ def statechart_parser_rules(globals, path, load_external = True, parse_f = parse
 
           def parse_attr_cond(cond):
             expr = parse_expression(globals, cond)
-            expr.init_expr(scope)
+            guard_type = expr.init_expr(scope)
+            if guard_type != SCCDBool:
+              raise XmlError("Guard should be an expression evaluating to 'bool'.")
             transition.guard = expr
 
           if_attribute(el, "event", parse_attr_event)

+ 0 - 17
test/test_files/todo/test_should_fail.xml

@@ -1,17 +0,0 @@
-<?xml version="1.0" ?>
-<test>
-  <statechart>
-    <!-- this test succeeds, but it should fail:
-         the transition's guard should have no access to the function 'f' declared in the transition's action code.
-         to fix this, the transition's action code should have its own scope (and hence, stack frame),
-         and so should the transition's guard.
-         the "transition scope" should only be used for event parameters.  -->
-    <root>
-      <state id="A">
-        <transition event="e(i: int)" guard="f(i) == 0" target=".">
-          <code> f = func(j: int) { return j+1; }; </code>
-        </transition>
-      </state>
-    </root>
-  </statechart>
-</test>

+ 11 - 0
test/test_files/xml_syntax/fail_guard_bool.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" ?>
+<test>
+  <statechart>
+    <root>
+      <state id="a">
+        <!-- guard condition is not an expression of boolean type -->
+        <transition cond="42 + 10" target="."/>
+      </state>
+    </root>
+  </statechart>
+</test>