about summary refs log tree commit diff stats
path: root/021check_instruction.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-04-18 18:04:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-04-18 18:04:50 -0700
commitf8b0b04da1d63dfb442fa547a82f98f1be14b446 (patch)
tree4f6c24ec8996ab7878caff8bcc90c392826c88e3 /021check_instruction.cc
parent04683e4ecec9bc26f0930a548fc2173d89f686c4 (diff)
downloadmu-f8b0b04da1d63dfb442fa547a82f98f1be14b446.tar.gz
3833
Loosen type-checking slightly to accomodate type abbreviations.
Diffstat (limited to '021check_instruction.cc')
-rw-r--r--021check_instruction.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc
index 90f24926..35b3eea0 100644
--- a/021check_instruction.cc
+++ b/021check_instruction.cc
@@ -146,7 +146,12 @@ bool types_strictly_match(const type_tree* to, const type_tree* from) {
     if (from->value == -1) return from->name == to->name;
     return from->value == to->value;
   }
-  return types_strictly_match(to->left, from->left) && types_strictly_match(to->right, from->right);
+  if (types_strictly_match(to->left, from->left) && types_strictly_match(to->right, from->right))
+    return true;
+  // fallback: (x) == x
+  if (to->right == NULL && types_strictly_match(to->left, from)) return true;
+  if (from->right == NULL && types_strictly_match(to, from->left)) return true;
+  return false;
 }
 
 void test_unknown_type_does_not_match_unknown_type() {
@@ -161,6 +166,16 @@ void test_unknown_type_matches_itself() {
   CHECK(types_strictly_match(a, b));
 }
 
+void test_type_abbreviations_match_raw_types() {
+  put(Type_abbreviations, "text", new_type_tree("address:array:character"));
+  // a has type (address buffer (address array character))
+  reagent a("a:address:buffer:text");
+  expand_type_abbreviations(a.type);
+  // b has type (address buffer address array character)
+  reagent b("b:address:buffer:address:array:character");
+  CHECK(types_strictly_match(a, b));
+}
+
 //: helpers
 
 bool is_unsafe(const reagent& r) {