diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-08 10:31:48 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-08 10:31:48 -0800 |
commit | 4ecab1821ed7609d35f2c9509cb045dc79606e8c (patch) | |
tree | c5f7f3641fd24fac4c36139a81fcddd4dab188e5 | |
parent | f4647409b5fa658e463424c0a8249a4d72405d59 (diff) | |
download | mu-4ecab1821ed7609d35f2c9509cb045dc79606e8c.tar.gz |
3653
Don't crash on bad types. I need to be more careful in distinguishing between the two causes of constraint violations: bad input and internal bugs. Maybe I should create a second assert() to indicate "this shouldn't really be an assert, but I'm too lazy to think about it right now."
-rw-r--r-- | 020run.cc | 5 | ||||
-rw-r--r-- | 021check_instruction.cc | 10 | ||||
-rw-r--r-- | 030container.cc | 5 | ||||
-rw-r--r-- | 036refcount.cc | 5 | ||||
-rw-r--r-- | 055shape_shifting_container.cc | 7 |
5 files changed, 27 insertions, 5 deletions
diff --git a/020run.cc b/020run.cc index de957dbb..b154b37d 100644 --- a/020run.cc +++ b/020run.cc @@ -335,7 +335,10 @@ int size_of(const type_tree* type) { // End size_of(type) Atom Special-cases } else { - assert(type->left->atom); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << '\n' << end(); + return 0; + } if (type->left->name == "address") return 1; // End size_of(type) Non-atom Special-cases } diff --git a/021check_instruction.cc b/021check_instruction.cc index c049d619..93ce5427 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -176,7 +176,10 @@ bool is_mu_array(const type_tree* type) { if (!type) return false; if (is_literal(type)) return false; if (type->atom) return false; - assert(type->left->atom); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << '\n' << end(); + return false; + } return type->left->value == get(Type_ordinal, "array"); } @@ -188,7 +191,10 @@ bool is_mu_address(const type_tree* type) { if (!type) return false; if (is_literal(type)) return false; if (type->atom) return false; - assert(type->left->atom); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << '\n' << end(); + return false; + } return type->left->value == get(Type_ordinal, "address"); } diff --git a/030container.cc b/030container.cc index 53efc857..098c38c5 100644 --- a/030container.cc +++ b/030container.cc @@ -204,7 +204,10 @@ void compute_container_sizes(const type_tree* type, set<type_tree>& pending_meta if (contains_key(pending_metadata, *type)) return; pending_metadata.insert(*type); if (!type->atom) { - assert(type->left->atom); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << location_for_error_messages << '\n' << end(); + return; + } if (type->left->name == "address") compute_container_sizes(type->right, pending_metadata, location_for_error_messages); // End compute_container_sizes Non-atom Special-cases diff --git a/036refcount.cc b/036refcount.cc index 36aea6c0..09bb5d30 100644 --- a/036refcount.cc +++ b/036refcount.cc @@ -311,7 +311,10 @@ void compute_container_address_offsets(reagent& r, const string& location_for_er void compute_container_address_offsets(const type_tree* type, const string& location_for_error_messages) { if (!type) return; if (!type->atom) { - assert(type->left->atom); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << location_for_error_messages << '\n' << end(); + return; + } if (type->left->name == "address") compute_container_address_offsets(type->right, location_for_error_messages); else if (type->left->name == "array") diff --git a/055shape_shifting_container.cc b/055shape_shifting_container.cc index 707ac125..061cd0ef 100644 --- a/055shape_shifting_container.cc +++ b/055shape_shifting_container.cc @@ -20,6 +20,13 @@ if (!base_type->atom) base_type = base_type->left; :(after "Update MAYBE_CONVERT base_type in Check") if (!base_type->atom) base_type = base_type->left; +:(scenario ill_formed_container) +% Hide_errors = true; +def main [ + {1: ((foo) num)} <- copy 0 +] +# no crash + :(scenario size_of_shape_shifting_container) container foo:_t [ x:_t |