Fix SC2329 false positive for functions referenced in prompt variables and command substitutions#2
Conversation
Co-authored-by: dotysan <5060170+dotysan@users.noreply.github.com>
…se-positive-sc2329
…with exit $? Co-authored-by: dotysan <5060170+dotysan@users.noreply.github.com>
|
@copilot No, you are off in the weeds again. This bug doesn't occur when f is called after f(). Nor is it sane t call f before f(). This is a special case with the bash PS4 variable. And oddly triggered by the existense of exit after them. Also the $? has no bearing here. PS4func() { echo 'hello' |
…nd substitutions Correctly recognize function references in: - Command substitutions $() and backticks - Prompt variables (PS1, PS2, PS3, PS4, PROMPT_COMMAND) Functions referenced in these contexts are considered invoked even if the function definition appears unreachable in the CFG. Co-authored-by: dotysan <5060170+dotysan@users.noreply.github.com>
You're absolutely right - I misunderstood the issue. The fix now correctly handles PS4 and other prompt variables (PS1, PS2, PS3, PROMPT_COMMAND) where functions are invoked indirectly through variable evaluation, even when the function is in single quotes. The fix detects function references in:
Fixed in commit 5fc9fbe. |
SC2329 incorrectly flagged functions as "never invoked" when they were referenced in prompt variables (PS1, PS2, PS3, PS4, PROMPT_COMMAND) or command substitutions, especially when scripts ended with
exit.Changes
checkCommandIsUnreachableinAnalytics.hs: AddedisFunctionReferencedInCommandSubstitutionhelper that detects function references in:$(funcname)or`funcname`prop_checkCommandIsUnreachable10(PS4 variable) andprop_checkCommandIsUnreachable11(backtick command substitution)returnoutside functionsThe fix correctly recognizes that functions referenced in prompt variables and command substitutions are invoked indirectly, preventing false positives while preserving correct behavior for truly uninvoked functions.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.