Skip to content

Fix another only written to unused variable case#1472

Open
keith wants to merge 3 commits into
bazelbuild:mainfrom
keith:ks/fix-another-only-written-to-unused-variable-case
Open

Fix another only written to unused variable case#1472
keith wants to merge 3 commits into
bazelbuild:mainfrom
keith:ks/fix-another-only-written-to-unused-variable-case

Conversation

@keith

@keith keith commented Jun 9, 2026

Copy link
Copy Markdown
Member

If you have an array was used like:

items = []
items.append(1)

This would be considered used even if it was never read. Now some known
functions are ignored so it can still be considered unused in this case.

If you have an array was used like:

```bzl
items = []
items.append(1)
```

This would be considered used even if it was never read. Now some known
functions are ignored so it can still be considered unused in this case.
@keith keith requested a review from a team as a code owner June 9, 2026 23:44
@keith keith requested review from oreflow and removed request for a team June 9, 2026 23:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to identify variables that are only mutated by methods returning "None" (such as "append", "clear", "extend", "insert", "remove", and "update") but never otherwise read, allowing them to be correctly flagged as unused. A review comment suggests adding the "sort" method to this list of mutating methods to ensure it is also covered.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread warn/warn_control_flow.go
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@keith

keith commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

hrm this heuristic might not work:

def foo(items):
    items.append(1)

this shows items as unused. let me see if i can exclude params

@keith

keith commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

that case is potentially fixable, but this case i found in rules_go is more problematic:

def apple_ensure_options(ctx, env, compiler_option_lists, linker_option_lists, target_gnu_system_name):
    """Returns environment and flags for Apple targets."""
    platform, platform_type = _PLATFORMS.get(target_gnu_system_name, (None, None))
    if not platform:
        return
    env.update(_apple_env(ctx, platform))
    min_version = _apple_version_min(ctx, platform, platform_type)
    for compiler_options in compiler_option_lists:
        compiler_options.append(min_version)
    for linker_options in linker_option_lists:
        linker_options.append(min_version)

here the logic diagnoses compiler_options as unused but it's mutating things again

@keith

keith commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

i pushed a fix that seems to handle both of these cases

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.

1 participant