diff options
-rw-r--r-- | 042name.cc | 13 | ||||
-rw-r--r-- | 056static_dispatch.cc | 20 | ||||
-rw-r--r-- | edit/010-errors.mu | 2 |
3 files changed, 26 insertions, 9 deletions
diff --git a/042name.cc b/042name.cc index 503589c7..d0d114fb 100644 --- a/042name.cc +++ b/042name.cc @@ -211,17 +211,18 @@ def main [ :(before "End transform_names(inst) Special-cases") // replace element names of containers with offsets if (inst.name == "get" || inst.name == "get-address" || inst.name == "put") { - if (SIZE(inst.ingredients) < 2) { - raise << maybe(get(Recipe, r).name) << "2 or more ingredients expected in '" << to_original_string(inst) << "'\n" << end(); - break; - } + //: avoid raising any errors here; later layers will support overloading new + //: instructions with the same names (static dispatch), which could lead to + //: spurious errors + if (SIZE(inst.ingredients) < 2) + break; // error raised elsewhere if (!is_literal(inst.ingredients.at(1))) - raise << maybe(get(Recipe, r).name) << "expected ingredient 1 of '" << inst.name << "' to have type 'offset'; got " << inst.ingredients.at(1).original_string << '\n' << end(); + break; // error raised elsewhere if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { // since first non-address in base type must be a container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); if (base_type == -1) - raise << maybe(get(Recipe, r).name) << "expected a container in '" << to_original_string(inst) << "'\n" << end(); + break; // error raised elsewhere if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); trace(9993, "name") << "element " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " is at offset " << no_scientific(inst.ingredients.at(1).value) << end(); diff --git a/056static_dispatch.cc b/056static_dispatch.cc index 8d1d27b7..1d57872d 100644 --- a/056static_dispatch.cc +++ b/056static_dispatch.cc @@ -134,7 +134,7 @@ for (int i = 0; i < SIZE(caller.products); ++i) check_or_set_invalid_types(caller.products.at(i).type, maybe(caller.name), "recipe header product"); //: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes) -:(after "End Type Modifying Transforms") +:(after "Transform.push_back(transform_names)") Transform.push_back(resolve_ambiguous_calls); // idempotent //: In a later layer we'll introduce recursion in resolve_ambiguous_calls, by @@ -545,5 +545,23 @@ def! foo x:address:number -> y:number [ +mem: storing 34 in location 2 $error: 0 +:(scenario dispatch_errors_come_after_unknown_name_errors) +% Hide_errors = true; +def main [ + y:number <- foo x +] +def foo a:number -> b:number [ + local-scope + load-ingredients + return 34 +] +def foo a:boolean -> b:number [ + local-scope + load-ingredients + return 35 +] ++error: main: missing type for x in 'y:number <- foo x' ++error: main: failed to find a matching call for 'y:number <- foo x' + :(before "End Includes") using std::abs; diff --git a/edit/010-errors.mu b/edit/010-errors.mu index ed3de58e..10ec43bd 100644 --- a/edit/010-errors.mu +++ b/edit/010-errors.mu @@ -461,8 +461,6 @@ recipe foo [ . y:address:shared:point <- new point:type ┊ . . get *y:address:shared:point, x:number ┊ . .] ┊ . - .foo: expected ingredient 1 of 'get' to have type ↩┊ . - .'offset'; got x:number ┊ . .foo: second ingredient of 'get' should have type ↩┊ . .'offset', but got x:number ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . |