diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 22:07:14 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 22:07:14 -0700 |
commit | 61880904a2f1446f331ac48ad56b3e7c006d0d55 (patch) | |
tree | d1e1581d39ea4e1751cd36a5cb3d90338dca1af6 | |
parent | 7f707a515eb26c4bcd4168412a0a1c65a81b1e05 (diff) | |
download | mu-61880904a2f1446f331ac48ad56b3e7c006d0d55.tar.gz |
3576
More helpful messages when people forget 'load-ingredients'.
-rw-r--r-- | 042name.cc | 2 | ||||
-rw-r--r-- | 053recipe_header.cc | 28 | ||||
-rw-r--r-- | 071recipe.cc | 14 |
3 files changed, 43 insertions, 1 deletions
diff --git a/042name.cc b/042name.cc index a23f3a6a..fbfa5d20 100644 --- a/042name.cc +++ b/042name.cc @@ -56,6 +56,7 @@ void transform_names(const recipe_ordinal r) { if (is_integer(ingredient.name)) continue; if (!already_transformed(ingredient, names)) { raise << maybe(caller.name) << "use before set: '" << ingredient.name << "'\n" << end(); + // use-before-set Error return; } int v = lookup_name(ingredient, r); @@ -98,6 +99,7 @@ void transform_names(const recipe_ordinal r) { bool is_disqualified(/*mutable*/ reagent& x, const instruction& inst, const string& recipe_name) { if (!x.type) { raise << maybe(recipe_name) << "missing type for '" << x.original_string << "' in '" << inst.original_string << "'\n" << end(); + // missing-type Error 1 return true; } if (is_raw(x)) return true; diff --git a/053recipe_header.cc b/053recipe_header.cc index fc6312b4..e6cc51d9 100644 --- a/053recipe_header.cc +++ b/053recipe_header.cc @@ -220,6 +220,34 @@ case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: { break; } +//: more useful error messages if someone forgets 'load-ingredients' + +:(scenario load_ingredients_missing_error) +% Hide_errors = true; +def foo a:num [ + local-scope + b:num <- add a:num, 1 +] ++error: foo: use before set: 'a' ++error: did you forget 'load-ingredients'? + +:(after "use-before-set Error") +if (is_present_in_ingredients(caller, ingredient.name)) + raise << " did you forget 'load-ingredients'?\n" << end(); + +:(scenario load_ingredients_missing_error_2) +% Hide_errors = true; +def foo a:num [ + local-scope + b:num <- add a, 1 +] ++error: foo: missing type for 'a' in 'b:num <- add a, 1' ++error: did you forget 'load-ingredients'? + +:(after "missing-type Error 1") +if (is_present_in_ingredients(get(Recipe, get(Recipe_ordinal, recipe_name)), x.name)) + raise << " did you forget 'load-ingredients'?\n" << end(); + //:: Check all calls against headers. :(scenario show_clear_error_on_bad_call) diff --git a/071recipe.cc b/071recipe.cc index 18861ad7..e08f75db 100644 --- a/071recipe.cc +++ b/071recipe.cc @@ -348,7 +348,19 @@ check_for_recipe_literals(inst, get(Recipe, r)); :(code) void check_for_recipe_literals(const instruction& inst, const recipe& caller) { for (int i = 0; i < SIZE(inst.ingredients); ++i) { - if (is_mu_recipe(inst.ingredients.at(i))) + if (is_mu_recipe(inst.ingredients.at(i))) { raise << maybe(caller.name) << "missing type for '" << inst.ingredients.at(i).original_string << "' in '" << inst.original_string << "'\n" << end(); + if (is_present_in_ingredients(caller, inst.ingredients.at(i).name)) + raise << " did you forget 'load-ingredients'?\n" << end(); + } } } + +:(scenario load_ingredients_missing_error_3) +% Hide_errors = true; +def foo {f: (recipe num -> num)} [ + local-scope + b:num <- call f, 1 +] ++error: foo: missing type for 'f' in 'b:num <- call f, 1' ++error: did you forget 'load-ingredients'? |