Skip to content

Commit

Permalink
Short-circuit if possible for start line and unused warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Oct 10, 2024
1 parent ba89182 commit 2745c81
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,20 +961,18 @@ pm_locals_order(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, pm_locals_t *locals,
if (local->name != PM_CONSTANT_ID_UNSET) {
pm_constant_id_list_insert(list, (size_t) local->index, local->name);

if (warn_unused && local->reads == 0) {
if (pm_newline_list_line(&parser->newline_list, local->location.start, parser->start_line) >= 0) {
pm_constant_t *constant = pm_constant_pool_id_to_constant(&parser->constant_pool, local->name);
if (warn_unused && local->reads == 0 && ((parser->start_line >= 0) || (pm_newline_list_line(&parser->newline_list, local->location.start, parser->start_line) >= 0))) {
pm_constant_t *constant = pm_constant_pool_id_to_constant(&parser->constant_pool, local->name);

if (constant->length >= 1 && *constant->start != '_') {
PM_PARSER_WARN_FORMAT(
parser,
local->location.start,
local->location.end,
PM_WARN_UNUSED_LOCAL_VARIABLE,
(int) constant->length,
(const char *) constant->start
);
}
if (constant->length >= 1 && *constant->start != '_') {
PM_PARSER_WARN_FORMAT(
parser,
local->location.start,
local->location.end,
PM_WARN_UNUSED_LOCAL_VARIABLE,
(int) constant->length,
(const char *) constant->start
);
}
}
}
Expand Down

0 comments on commit 2745c81

Please sign in to comment.