about summary refs log tree commit diff stats
path: root/021check_instruction.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-01-30 22:17:36 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-01-30 22:17:36 -0800
commit3bfd75fcf0eacdab7e26700fee92327cfbf420a5 (patch)
tree4df239b46e0cef1ca2ababaec7c794a04cf7d157 /021check_instruction.cc
parent007382e2a92b743ba50e6bd87d637ff7c559212f (diff)
downloadmu-3bfd75fcf0eacdab7e26700fee92327cfbf420a5.tar.gz
2619 - actually allow coercing booleans to numbers
This uncovered a bug where I've been forgetting the directionality of
arguments to types_coercible().
Diffstat (limited to '021check_instruction.cc')
-rw-r--r--021check_instruction.cc22
1 files changed, 19 insertions, 3 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc
index 58fd395f..03f1cc61 100644
--- a/021check_instruction.cc
+++ b/021check_instruction.cc
@@ -81,11 +81,21 @@ recipe main [
 +mem: storing 12 in location 2
 $error: 0
 
+:(scenario write_boolean_to_number_allowed)
+% Hide_errors = true;
+recipe main [
+  1:boolean <- copy 1/true
+  2:number <- copy 1:boolean
+]
++mem: storing 1 in location 2
+$error: 0
+
 :(code)
 // types_match with some leniency
-bool types_coercible(const reagent& lhs, const reagent& rhs) {
-  if (types_match(lhs, rhs)) return true;
-  if (is_mu_address(rhs) && is_mu_number(lhs)) return true;
+bool types_coercible(const reagent& to, const reagent& from) {
+  if (types_match(to, from)) return true;
+  if (is_mu_address(from) && is_mu_number(to)) return true;
+  if (is_mu_boolean(from) && is_mu_number(to)) return true;
   // End types_coercible Special-cases
   return false;
 }
@@ -152,6 +162,12 @@ bool is_mu_address(reagent r) {
   return r.type->value == get(Type_ordinal, "address");
 }
 
+bool is_mu_boolean(reagent r) {
+  if (!r.type) return false;
+  if (is_literal(r)) return false;
+  return r.type->value == get(Type_ordinal, "boolean");
+}
+
 bool is_mu_number(reagent r) {
   if (!r.type) return false;
   if (is_literal(r)) {