Skip to content
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

Variable incorrectly nil during rdoc test suite #3377

Closed
eregon opened this issue Jan 11, 2024 · 3 comments
Closed

Variable incorrectly nil during rdoc test suite #3377

eregon opened this issue Jan 11, 2024 · 3 comments
Assignees
Labels

Comments

@eregon
Copy link
Member

eregon commented Jan 11, 2024

Originally reported by @nobu on Slack.

Can be seen at https://github.com/nobu/rdoc/actions/runs/7484932428/job/20372568997#step:6:37
And I could also reproduce locally for ruby/rdoc@4e14158 and
truffleruby 24.0.0-dev-286d3a41, like ruby 3.2.2, GraalVM CE Native [x86_64-linux] 286d3a41.

git clone rdoc
cd rdoc
bundle install
bundle exec rake
==============================================================================================================================
Error: test_can_parse_modeline_c(TestRDocParser): NoMethodError: undefined method `casecmp?' for nil:NilClass
/home/eregon/code/rdoc/lib/rdoc/parser.rb:131:in `block in can_parse_by_name'
<internal:core> core/enumerable.rb:713:in `block in find'
<internal:core> core/enumerable.rb:711:in `each'
<internal:core> core/enumerable.rb:711:in `find'
/home/eregon/code/rdoc/lib/rdoc/parser.rb:131:in `can_parse_by_name'
/home/eregon/code/rdoc/lib/rdoc/parser.rb:108:in `can_parse'
/home/eregon/code/rdoc/test/rdoc/test_rdoc_parser.rb:163:in `test_can_parse_modeline_c'
     160:       io.puts "/* This document explains how to make extension libraries for Ruby. */"
     161:     end
     162: 
  => 163:     assert_equal RDoc::Parser::C, @RP.can_parse(readme_inc)
     164:   ensure
     165:     File.unlink readme_inc
     166:   end
<internal:core> core/throw_catch.rb:36:in `catch'
<internal:core> core/throw_catch.rb:36:in `catch'
==============================================================================================================================

But looking at the code it's clear mode cannot be nil there:
https://github.com/ruby/rdoc/blob/4e14158255ad8de64041105470d88f66b6e22e98/lib/rdoc/parser.rb#L128-L131

Interestingly it happens with export TRUFFLERUBYOPT="--experimental-options --engine.Compilation=false" too.

And it also happens on truffleruby-jvm.
Can be reproduced with just be ruby -Ilib test/rdoc/test_rdoc_parser.rb.

@eregon eregon added the bug label Jan 11, 2024
@eregon
Copy link
Member Author

eregon commented Jan 11, 2024

Changing

case mode = check_modeline(file_name)

to

mode = check_modeline(file_name)
case mode

works.

So it looks like the variable is declared at the wrong level or something.

@eregon
Copy link
Member Author

eregon commented Jan 11, 2024

Minimal repro:

def test(a)
  case mode = a
  when nil
  else
    self.then { mode.casecmp?("foo") }
  end
end

p test("c")

gives

repro_rdoc.rb:5:in `block in test': undefined method `casecmp?' for nil:NilClass (NoMethodError)
	from <internal:core> core/kernel.rb:523:in `yield_self'
	from repro_rdoc.rb:5:in `test'
	from repro_rdoc.rb:9:in `<main>'

(but it should print false)

@eregon eregon self-assigned this Jan 11, 2024
@eregon
Copy link
Member Author

eregon commented Jan 11, 2024

Fix in #3378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant