From 3bfd75fcf0eacdab7e26700fee92327cfbf420a5 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 30 Jan 2016 22:17:36 -0800 Subject: 2619 - actually allow coercing booleans to numbers This uncovered a bug where I've been forgetting the directionality of arguments to types_coercible(). --- 021check_instruction.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to '021check_instruction.cc') 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)) { -- cgit 1.4.1-2-gfad0