GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Match MRI for "assigned but unused variable" warnings by sampokuokkanen · Pull Request #10046 · jruby/jruby

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

With -w, JRuby's parser reported unused local variables differently from CRuby in a few places. Now it matches CRuby 4.0:

Code Before After (same as CRuby)
ruby -w script.rb with top-level a = 1 (also in required files) silent warns
echo 'a = 1' | ruby -w - silent warns
ruby -we "1.times do\n a = 1\nend" warns silent
eval("1.times do\n a = 1\nend") warns silent

Two causes:

  • The top-level scope is never popped, so its unused variables were never reported. finalizeDynamicScope now reports them.
  • Pushing a block or method scope reset the warning flag from -w alone, which lost the exception for the top level of eval and -e. Like MRI's local_push and dyna_push, a block now keeps its enclosing scope's setting, and a method scope sets its own and restores the old one when popped.

This un-excludes TestRubyOptions#test_unused_variable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sampokuokkanen
Match MRI for "assigned but unused variable" warnings
2eac35d
The top-level scope is never popped, so warnUnusedVariables never ran
for it, and unused top-level variables were never reported. Report them
from finalizeDynamicScope instead, using the lexer's file because a
reused TOPLEVEL_BINDING scope has no file of its own.

pushBlockScope and pushLocalScope set warnOnUnusedVariables from
isVerbose() alone. That dropped the eval and -e exception that
initTopLocalVariables had just set up, and popCurrentScope never
restored the old value. As in MRI's dyna_push, a block now keeps the
setting of its enclosing scope, and a local scope saves the old setting
and restores it when popped.

With -w, now matching CRuby:

  ruby -w script.rb (top-level a = 1)     now warns (was silent),
                                          also for required files
  echo 'a = 1' | ruby -w -                now warns (was silent)
  ruby -we "1.times do\n  a = 1\nend"     now silent (was warning)
  eval("1.times do\n  a = 1\nend")        now silent (was warning)

Unexcludes TestRubyOptions#test_unused_variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sampokuokkanen
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.