2 次代码提交 ecf669425f ... ad6fcd7a24

作者 SHA1 备注 提交日期
  Joeri Exelmans ad6fcd7a24 add type check when overwriting slot value 6 月之前
  Joeri Exelmans a245d0a406 add a todo thingy 6 月之前
共有 2 个文件被更改,包括 12 次插入1 次删除
  1. 3 1
      TODO.txt
  2. 9 0
      api/od.py

+ 3 - 1
TODO.txt

@@ -29,7 +29,9 @@ Feature requests:
 
   - When matching edge, match 'any' src/tgt
 
-  - Support 'return'-statement in conditions?
+  - Support 'return'-statement in conditions? (just makes syntax nicer)
+
+  - RAMification / matching: add `match_subtypes` attribute to each RAMified class.
 
   - Separate script for running LHS (+NAC) on any model, and visualizing the match.
 

+ 9 - 0
api/od.py

@@ -215,16 +215,25 @@ class ODAPI:
 
     def overwrite_primitive_value(self, name: str, value: any, is_code=False):
         referred_model = UUID(self.bottom.read_value(self.get(name)))
+        to_overwrite_type = self.get_type_name(self.get(name))
         # watch out: in Python, 'bool' is subtype of 'int'
         #  so we must check for 'bool' first
         if isinstance(value, bool):
+            if to_overwrite_type != "Boolean":
+                raise Exception(f"Cannot assign boolean value '{value}' to value of type {to_overwrite_type}.")
             Boolean(referred_model, self.state).create(value)
         elif isinstance(value, int):
+            if to_overwrite_type != "Integer":
+                raise Exception(f"Cannot assign integer value '{value}' to value of type {to_overwrite_type}.")
             Integer(referred_model, self.state).create(value)
         elif isinstance(value, str):
             if is_code:
+                if to_overwrite_type != "ActionCode":
+                    raise Exception(f"Cannot assign code to value of type {to_overwrite_type}.")
                 ActionCode(referred_model, self.state).create(value)
             else:
+                if to_overwrite_type != "String":
+                    raise Exception(f"Cannot assign string value '{value}' to value of type {to_overwrite_type}.")
                 String(referred_model, self.state).create(value)
         else:
             raise Exception("Unimplemented type "+value)