Fix another only written to unused variable case#1472
Conversation
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.
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
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 |
|
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 |
|
i pushed a fix that seems to handle both of these cases |
If you have an array was used like:
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.