diff --git a/src/runtime/error_costs.c b/src/runtime/error_costs.c index ac055f45..99e346f1 100644 --- a/src/runtime/error_costs.c +++ b/src/runtime/error_costs.c @@ -2,6 +2,8 @@ static const unsigned MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE; static const unsigned MAX_PUSH_COUNT_WITH_COUNT_DIFFERENCE = 24; +static const unsigned MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE = 32; +static const unsigned MAX_DEPTH_TO_ALLOW_MULTIPLE = 12; ErrorComparison error_status_compare(ErrorStatus a, ErrorStatus b, bool are_mergeable) { if (a.count < b.count) { @@ -42,5 +44,20 @@ ErrorComparison error_status_compare(ErrorStatus a, ErrorStatus b, bool are_merg } } + if (a.count > 0) { + if (a.push_count > MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE || + b.push_count > MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE || + a.depth > MAX_DEPTH_TO_ALLOW_MULTIPLE || + b.depth > MAX_DEPTH_TO_ALLOW_MULTIPLE) { + return a.depth <= b.depth ? + ErrorComparisonTakeLeft : + ErrorComparisonTakeRight; + } else { + return a.depth <= b.depth ? + ErrorComparisonPreferLeft : + ErrorComparisonPreferRight; + } + } + return ErrorComparisonNone; } diff --git a/src/runtime/error_costs.h b/src/runtime/error_costs.h index 968c2422..f65b9c93 100644 --- a/src/runtime/error_costs.h +++ b/src/runtime/error_costs.h @@ -16,6 +16,7 @@ typedef struct { unsigned count; unsigned cost; unsigned push_count; + unsigned depth; } ErrorStatus; typedef enum { diff --git a/src/runtime/stack.c b/src/runtime/stack.c index d244fab0..71d3e32a 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -384,6 +384,7 @@ ErrorStatus ts_stack_error_status(const Stack *self, StackVersion version) { .cost = head->node->error_cost, .count = head->node->error_count, .push_count = head->push_count, + .depth = head->depth, }; } diff --git a/test/fixtures/error_corpus/javascript_errors.txt b/test/fixtures/error_corpus/javascript_errors.txt index 02edfb48..2a4b3bba 100644 --- a/test/fixtures/error_corpus/javascript_errors.txt +++ b/test/fixtures/error_corpus/javascript_errors.txt @@ -30,9 +30,8 @@ h i j k; (program (if_statement - (ERROR (identifier)) + (ERROR (identifier) (identifier)) (identifier) - (ERROR (identifier)) (statement_block (expression_statement (identifier)