diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-07-08 21:34:52 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-07-08 21:34:52 -0700 |
commit | 9e32e4736dc12479e3855e8d29ba7ecb6ac50ff6 (patch) | |
tree | 0fb382ddb830843b0993da27ff24900c59f18b60 /021check_instruction.cc | |
parent | 0f0be736fbe118612ad0b8f2bd84c2e7f4c35ade (diff) | |
download | mu-9e32e4736dc12479e3855e8d29ba7ecb6ac50ff6.tar.gz |
3963
Narrow the scope of implicit type conversions. Now only numbers can be freely converted to from other scalars (booleans, characters). We want in particular to make this an error: x:character <- new [abc]
Diffstat (limited to '021check_instruction.cc')
-rw-r--r-- | 021check_instruction.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc index b8aa3663..a32c6178 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -79,6 +79,14 @@ def main [ +mem: storing 12 in location 2 $error: 0 +:(scenario write_address_to_character_disallowed) +% Hide_errors = true; +def main [ + 1:address:num <- copy 12/unsafe + 2:char <- copy 1:address:num +] ++error: main: can't copy '1:address:num' to '2:char'; types don't match + :(scenario write_boolean_to_number_allowed) def main [ 1:bool <- copy 1/true @@ -87,21 +95,20 @@ def main [ +mem: storing 1 in location 2 $error: 0 -:(scenario write_number_to_boolean_allowed) +:(scenario write_number_to_boolean_disallowed) +% Hide_errors = true; def main [ 1:num <- copy 34 2:bool <- copy 1:num ] -+mem: storing 34 in location 2 -$error: 0 ++error: main: can't copy '1:num' to '2:bool'; types don't match :(code) // types_match with some leniency 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; - if (is_mu_number(from) && is_mu_boolean(to)) return true; + if (is_mu_address(from) && is_real_mu_number(to)) return true; + if (is_mu_boolean(from) && is_real_mu_number(to)) return true; // End types_coercible Special-cases return false; } @@ -223,6 +230,11 @@ bool is_mu_boolean(reagent/*copy*/ r) { } bool is_mu_number(reagent/*copy*/ r) { + if (is_mu_character(r.type)) return true; // permit arithmetic on unicode code points + return is_real_mu_number(r); +} + +bool is_real_mu_number(reagent/*copy*/ r) { // End Preprocess is_mu_number(reagent r) if (!r.type) return false; if (!r.type->atom) return false; @@ -230,7 +242,6 @@ bool is_mu_number(reagent/*copy*/ r) { return r.type->name == "literal-fractional-number" || r.type->name == "literal"; } - if (r.type->value == get(Type_ordinal, "character")) return true; // permit arithmetic on unicode code points return r.type->value == get(Type_ordinal, "number"); } |