Skip to content

Warn on class/const assign in condition#9404

Merged
enebo merged 2 commits into
jruby:masterfrom
sampokuokkanen:test_assign_in_conditional
May 2, 2026
Merged

Warn on class/const assign in condition#9404
enebo merged 2 commits into
jruby:masterfrom
sampokuokkanen:test_assign_in_conditional

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented May 1, 2026

Copy link
Copy Markdown
Contributor

Extend checkAssignmentInCondition to treat ClassVarAsgnNode and ConstDeclNode as assignable nodes so assignments like class vars or constant declarations in conditionals will trigger the existing "assignment in conditional" warning. Also re-enable the test_assign_in_conditional test by removing its exclude in test/mri/excludes/TestParse.rb.

So code like following:

if @@hello = true
  pp "hello"
end

and

if BASE_HELLO = true
  pp "hello"
end

will now have the found '= literal' in conditional, should be == warning.

Sorry about the Copilot review, I have now disabled it so it will no longer auto review my PRs from now on.

Extend checkAssignmentInCondition to treat ClassVarAsgnNode and ConstDeclNode as assignable nodes so assignments like class vars or constant declarations in conditionals will trigger the existing "assignment in conditional" warning. Also re-enable the test_assign_in_conditional test by removing its exclude in test/mri/excludes/TestParse.rb.
Copilot AI review requested due to automatic review settings May 1, 2026 01:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Extends JRuby’s existing “assignment in conditional” warning to also catch class variable assignments and constant declarations used as conditional expressions, and re-enables the corresponding MRI parsing test.

Changes:

  • Updated checkAssignmentInCondition to treat ClassVarAsgnNode and ConstDeclNode as assignable nodes eligible for the warning.
  • Re-enabled the MRI test test_assign_in_conditional by removing its exclusion.

Reviewed changes

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

File Description
test/mri/excludes/TestParse.rb Removes the exclusion so test_assign_in_conditional runs again.
core/src/main/java/org/jruby/parser/RubyParserBase.java Expands assignment-node detection in conditionals to include class var and constant assignment nodes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@enebo

enebo commented May 2, 2026

Copy link
Copy Markdown
Member

@sampokuokkanen sorry I missed this one. I think it looks good but it required a merge so I will merge this once that completes. Looks like the right change and we love to see tests untagged!

@enebo enebo added this to the JRuby 10.1.1.0 milestone May 2, 2026
@enebo
enebo enabled auto-merge May 2, 2026 16:06
@enebo
enebo disabled auto-merge May 2, 2026 16:06
@enebo
enebo merged commit bd0737c into jruby:master May 2, 2026
108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants