diff --git a/flamingo/grammar/map.h b/flamingo/grammar/map.h index 75fd8fd..f9a68e8 100644 --- a/flamingo/grammar/map.h +++ b/flamingo/grammar/map.h @@ -38,7 +38,7 @@ static int parse_map(flamingo_t* flamingo, TSNode node, flamingo_val_t** val) { vals = realloc(vals, count * sizeof *vals); assert(vals != NULL); - // Parse key and value expressions. + // Parse key expression. flamingo_val_t* k = NULL; @@ -49,6 +49,19 @@ static int parse_map(flamingo_t* flamingo, TSNode node, flamingo_val_t** val) { return -1; } + // Make sure key doesn't already exist in map. + + for (size_t j = 0; j < count - 1; j++) { + if (val_eq(keys[j], k)) { + free(keys); + free(vals); + + return error(flamingo, "duplicate key in map"); + } + } + + // Parse value expression. + flamingo_val_t* v = NULL; if (parse_expr(flamingo, val_node, &v, NULL) < 0) {