Skip to content

Fix code that triggers warnings when compiled with Sorbet #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 12, 2025

I was testing the latest c-api commit against Sorbet, and I found a few warnings that need to be addressed:

Avoid declaring unused node variables in rbs_node_destroy's template

Such declarations will fail Sorbet's compiler:

prism/templates/src/ast.c.erb:203:31: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_annotation_t *node = (rbs_ast_annotation_t *)any_node;
                              ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_comment_t *node = (rbs_ast_comment_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_integer_t *node = (rbs_ast_integer_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:27: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_string_t *node = (rbs_ast_string_t *)any_node;
                          ^

Use size_t instead of int for capacity in rbs_loc_alloc_children

This fixes a warning about comparing int and size_t in rbs_loc_alloc_children's assertion.

Avoid declaring the max variable that's just used in assertions

When the assert is stripped out, the variable becomes unused and triggers a warning.

external/rbs_parser/src/rbs_location.c:8:10: warning: unused variable 'max' [-Wunused-variable]
  size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
         ^

@st0012 st0012 requested review from Morriar and amomchilov March 12, 2025 16:02
@st0012 st0012 changed the title Avoid declaring unused node variables in rbs_node_destroy's template Fix code that triggers warnings when compiled with Sorbet Mar 12, 2025
st0012 added 2 commits March 12, 2025 16:38
Such declarations will fail Sorbet's compiler:

```
prism/templates/src/ast.c.erb:203:31: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_annotation_t *node = (rbs_ast_annotation_t *)any_node;
                              ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_comment_t *node = (rbs_ast_comment_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_integer_t *node = (rbs_ast_integer_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:27: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_string_t *node = (rbs_ast_string_t *)any_node;
                          ^
```
- Use `size_t` instead of `int` for `capacity` in `rbs_loc_alloc_children`
  This fixes a warning about comparing `int` and `size_t` in
  `rbs_loc_alloc_children`'s assertion.
- Avoid declaring the `max` variable that's just used in assertions.
  When the `assert` is stripped out, the variable becomes unused and
  triggers a warning.
@st0012 st0012 force-pushed the avoid-declaring-unused-variables branch from 541cbe4 to 55fb761 Compare March 12, 2025 16:38
@st0012 st0012 merged commit 260670d into c-api Mar 12, 2025
19 checks passed
st0012 added a commit that referenced this pull request Mar 13, 2025
### Avoid declaring unused `node` variables in `rbs_node_destroy`'s template

Such declarations will fail Sorbet's compiler:

```
prism/templates/src/ast.c.erb:203:31: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_annotation_t *node = (rbs_ast_annotation_t *)any_node;
                              ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_comment_t *node = (rbs_ast_comment_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_integer_t *node = (rbs_ast_integer_t *)any_node;
                           ^
prism/templates/src/ast.c.erb:203:27: error: unused variable 'node' [-Werror,-Wunused-variable]
        rbs_ast_string_t *node = (rbs_ast_string_t *)any_node;
                          ^
```

### Use `size_t` instead of `int` for `capacity` in `rbs_loc_alloc_children`

This fixes a warning about comparing `int` and `size_t` in `rbs_loc_alloc_children`'s assertion.

### Avoid declaring the `max` variable that's just used in assertions

When the `assert` is stripped out, the variable becomes unused and triggers a warning.

```
external/rbs_parser/src/rbs_location.c:8:10: warning: unused variable 'max' [-Wunused-variable]
  size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
         ^
```
@st0012 st0012 deleted the avoid-declaring-unused-variables branch March 17, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants