Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
3752 - fix a couple of segfaults
Browse files Browse the repository at this point in the history
Thanks Ella Couch for running into these.
  • Loading branch information
akkartik committed Mar 3, 2017
1 parent e520e79 commit b5f2a62
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 360 deletions.
1 change: 1 addition & 0 deletions 021check_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool types_match(const reagent& to, const reagent& from) {
//: copy arguments for later layers
bool types_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from) {
// End Preprocess types_strictly_match(reagent to, reagent from)
if (to.type == NULL) return false; // error
if (is_literal(from) && to.type->value == get(Type_ordinal, "number")) return true;
// to sidestep type-checking, use /unsafe in the source.
// this will be highlighted in red inside vim. just for setting up some tests.
Expand Down
24 changes: 21 additions & 3 deletions 053recipe_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,29 @@ def foo -> x:num [

:(scenario recipe_headers_check_for_duplicate_names)
% Hide_errors = true;
def add2 x:num, x:num -> z:num [
def foo x:num, x:num -> z:num [
local-scope
load-ingredients
return z
]
+error: add2: 'x' can't repeat in the ingredients
+error: foo: 'x' can't repeat in the ingredients
:(scenario recipe_headers_check_for_duplicate_names_2)
% Hide_errors = true;
def foo x:num, x:num [ # no result
local-scope
load-ingredients
]
+error: foo: 'x' can't repeat in the ingredients

:(scenario recipe_headers_check_for_missing_types)
% Hide_errors = true;
def main [
foo 0
]
def foo a [ # no type for 'a'
]
+error: foo: ingredient 'a' has no type

:(before "End recipe Fields")
map<string, int> ingredient_index;
Expand All @@ -381,10 +398,11 @@ Transform.push_back(check_header_ingredients); // idempotent
:(code)
void check_header_ingredients(const recipe_ordinal r) {
recipe& caller_recipe = get(Recipe, r);
if (caller_recipe.products.empty()) return;
caller_recipe.ingredient_index.clear();
trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end();
for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
if (caller_recipe.ingredients.at(i).type == NULL)
raise << maybe(caller_recipe.name) << "ingredient '" << caller_recipe.ingredients.at(i).name << "' has no type\n" << end();
if (contains_key(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name))
raise << maybe(caller_recipe.name) << "'" << caller_recipe.ingredients.at(i).name << "' can't repeat in the ingredients\n" << end();
put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i);
Expand Down
Loading

0 comments on commit b5f2a62

Please sign in to comment.