diff options
-rw-r--r-- | 042name.cc | 12 | ||||
-rw-r--r-- | 059shape_shifting_recipe.cc | 19 |
2 files changed, 27 insertions, 4 deletions
diff --git a/042name.cc b/042name.cc index b25ca533..e9812624 100644 --- a/042name.cc +++ b/042name.cc @@ -204,8 +204,10 @@ if (inst.name == "get" || inst.name == "get-address") { 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, get(Recipe, r).name); - 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(); + 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(); + } } } @@ -243,7 +245,9 @@ if (inst.name == "maybe-convert") { if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { // since first non-address in base type must be an exclusive container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type, get(Recipe, r).name); - inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); - trace(9993, "name") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end(); + 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") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end(); + } } } diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index 7f224d15..b3fec956 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -673,3 +673,22 @@ container d1:_elem [ +error: foo: unknown type for e (check the name for typos) +error: specializing foo: missing type for e # and it doesn't crash + +:(scenario missing_type_in_shape_shifting_recipe_2) +% Hide_errors = true; +recipe main [ + a:d1:number <- merge 3 + foo a +] +recipe foo a:d1:_elem -> b:number [ + local-scope + load-ingredients + get e, x:offset # unknown variable in a 'get', which does some extra checking + reply 34 +] +container d1:_elem [ + x:_elem +] ++error: foo: unknown type for e (check the name for typos) ++error: specializing foo: missing type for e +# and it doesn't crash |