Skip to content

Go: Remove redundant code in IR::ExtractTupleElementInstruction.getResultType() and expand tests #19484

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 3 commits into from
May 14, 2025

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented May 13, 2025

I saw a minor edge case bug (CallExpr.getTarget() is not defined when we are calling a variable - we can instead use CallExpr.getCalleeType() when we just want the type of the target), but it turned out to be in redundant code, so I expanded our tests to confirm this and deleted the redundant code.

owen-mc added 3 commits May 13, 2025 15:48
The case of a CallExpr is actually covered by the next disjunct.

Note that the CallExpr case had a subtle bug: `c.getTarget()` is not
defined when we are calling a variable. Better to use
`c.getCalleeType()`. But in this case we can just delete the code.
@Copilot Copilot AI review requested due to automatic review settings May 13, 2025 15:02
@owen-mc owen-mc requested a review from a team as a code owner May 13, 2025 15:02
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label May 13, 2025
@github-actions github-actions bot added the Go label May 13, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes obsolete branching in ExtractTupleElementInstruction.getResultType() and extends IR tests to cover nested function calls, including calls via variables.

  • Deleted redundant CallExpr-specific logic in getResultType()
  • Added testNestedFunctionCalls in test.go to verify direct and variable-based calls
  • Updated test.ql and test.expected to select and assert on base instruction, index, and result type

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
go/ql/test/library-tests/semmle/go/IR/test.ql Expanded query to bind base, index, and resultType
go/ql/test/library-tests/semmle/go/IR/test.go Added nested call test covering variable callee
go/ql/test/library-tests/semmle/go/IR/test.expected Updated expected results for new test cases
go/ql/lib/semmle/go/controlflow/IR.qll Removed redundant CallExpr branch in getResultType()

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

While in theory target-type could be more specific, I don't think that can happen specifically with getTarget which only gives the type of the direct referee; if we used getACallee instead that could have potentially yielded a tighter bound on the actual result type.

@owen-mc owen-mc merged commit 8f5a2a9 into github:main May 14, 2025
17 checks passed
@owen-mc owen-mc deleted the go/minor-fix branch May 14, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants