Skip to content

Ruby: add qltest documenting implicit return dataflow gaps - #22272

Merged
aschackmull merged 2 commits into
mainfrom
copilot/add-qltest-documenting-existing-behavior
Aug 4, 2026
Merged

Ruby: add qltest documenting implicit return dataflow gaps#22272
aschackmull merged 2 commits into
mainfrom
copilot/add-qltest-documenting-existing-behavior

Conversation

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Ruby's dataflow ExprReturnNode only recognises implicit returns that are direct statements of the method body (c.getBody().getAStmt()), missing cases where the returned value is in a rescue, else, or a body with ensure present.

New test: implicit-return

Six cases, all using implicit returns (no return keyword):

# Works: simple body return
def m_body
  source(1)
end
sink(m_body) # $ hasValueFlow=1

# Missing: body return when ensure is present
def m_body_ensure
  source(2)
ensure
  nil
end
sink(m_body_ensure) # $ MISSING: hasValueFlow=2

# Missing: rescue clause
def m_rescue
  raise "error"
rescue
  source(3)
end
sink(m_rescue) # $ MISSING: hasValueFlow=3

# Also MISSING: rescue+ensure, else, else+ensure

MISSING: annotations document known gaps without causing test failures; the framework will emit "Fixed missing result" when the bug is eventually addressed.

Documents existing behavior for implicit returns (no return keyword)
from:
- method body with ensure present
- rescue clause (with and without ensure)
- else clause (with and without ensure)

The test shows that only simple body returns currently work; all other
cases are marked MISSING to document the known gaps.
Copilot AI changed the title Ruby: add qltest for implicit return steps Ruby: add qltest documenting implicit return dataflow gaps Aug 3, 2026
Copilot AI requested a review from aschackmull August 3, 2026 12:59

@aschackmull aschackmull 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.

Tweaks

Comment thread ruby/ql/test/library-tests/dataflow/implicit-return/implicit_return.rb Outdated
Comment thread ruby/ql/test/library-tests/dataflow/implicit-return/implicit_return.rb Outdated
Comment thread ruby/ql/test/library-tests/dataflow/implicit-return/implicit_return.rb Outdated
Comment thread ruby/ql/test/library-tests/dataflow/implicit-return/implicit_return.rb Outdated
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
@github-actions github-actions Bot added the Ruby label Aug 4, 2026
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Aug 4, 2026
@aschackmull
aschackmull marked this pull request as ready for review August 4, 2026 06:58
@aschackmull
aschackmull requested a review from a team as a code owner August 4, 2026 06:58
Copilot AI balanced review requested due to automatic review settings August 4, 2026 06:58

Copilot AI 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.

Pull request overview

Adds a focused Ruby data-flow regression test documenting known implicit-return gaps.

Changes:

  • Covers method body, rescue, and else implicit returns with optional ensure.
  • Marks known missing flows without failing the test.
Show a summary per file
File Description
implicit-return.ql Defines the path query.
implicit-return.expected Records current results.
implicit_return.rb Provides inline flow cases and expectations.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +3 to +4
# An implicit return is when no `return` statement is used; instead the
# last evaluated expression is returned.
@aschackmull
aschackmull merged commit 70bfecc into main Aug 4, 2026
12 checks passed
@aschackmull
aschackmull deleted the copilot/add-qltest-documenting-existing-behavior branch August 4, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Ruby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants