-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Bug/kernel#warn uplevel #2442
Bug/kernel#warn uplevel #2442
Conversation
7b1b772
to
74a092f
Compare
.travis.yml
Outdated
@@ -8,6 +8,7 @@ branches: | |||
- trying | |||
- /^[\d.]+$/ | |||
- /.+-stable$/ | |||
- /^bug\// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding this shouldn't be necessary, since you're making a PR into a branch that's already tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fork. Fork. Fork. Nothing is nicer than working on a PR in one's fork and discovering that you can't run a test on it because the branch name isn't allowed.
Also, I think it's also used in another popular repo, one that Nobu and some others here occasionally contribute to...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the last commit is unnecessary, and I'll remove it.
It is just to run CIs before creating this PR.
appveyor.yml
Outdated
@@ -4,6 +4,7 @@ branches: | |||
- master | |||
- auto | |||
- /[\d.]+/ | |||
- /^bug/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the PR!
If you could revert 7506506 (which made unnecessary CI changes) and address the comments I made, that'd be fantastic. 🙂
Let me know if you need clarifications on any of my comments, or if you need any help!
lib/rubygems/core_ext/kernel_warn.rb
Outdated
|
||
module_function define_method(:warn) {|*messages, uplevel: nil| | ||
if uplevel | ||
uplevel, = [uplevel].pack("l!").unpack("l!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this even doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting uplevel
to an Integer
which fits long
, with calling to_int
if needed.
There is no such method right now.
lib/rubygems/core_ext/kernel_warn.rb
Outdated
start = 0 | ||
begin | ||
loc, = caller_locations(start, 1) | ||
break start += uplevel unless loc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit more readable:
unless loc
start += uplevel
break start
end
lib/rubygems/core_ext/kernel_warn.rb
Outdated
loc, = caller_locations(start, 1) | ||
break start += uplevel unless loc | ||
start += 1 | ||
end while (loc.path.start_with?(path) or (uplevel -= 1) >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things with how this loop is done:
loop do
/end
and a conditionalbreak
is generally preferable overbegin
/end while ...
.- Please avoid assignments in conditions, especially complicated conditions like this one.
* lib/rubygems/core_ext/kernel_warn.rb (Kernel#warn): skip kernel_require.rb's frames when `uplevel` option is given.
bcc81f8
to
edfe2ac
Compare
* added comments * prefer `while` over `begin`/`end while` * prefer guard clauase over `if`..`else` * avoid assignments in conditions
edfe2ac
to
98b351d
Compare
Thanks for the PR, @nobu! @bundlerbot r+ |
2442: Bug/kernel#warn uplevel r=duckinator a=nobu # Description: With this script `w.rb`: ```ruby require "Win32API" ``` The expected line is shown when rubygems is disabled. ``` $ ruby -w --disable=gems -I./lib -I./ext/win32/lib w.rb w.rb:1: warning: Win32API is deprecated after Ruby 1.9.1; use fiddle directly instead ``` But `kernel_require.rb` is shown when rubygems is enabled. ``` $ ruby -w --enable=gems -I./lib -I./ext/win32/lib w.rb /opt/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54: warning: Win32API is deprecated after Ruby 1.9.1; use fiddle directly instead ``` ______________ # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [ ] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md). Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
@nobu by the way, thank you for taking the time to explain the parts of this PR I asked about. The |
Build succeeded |
I believe this PR/commit includes the file |
Description:
With this script
w.rb
:The expected line is shown when rubygems is disabled.
But
kernel_require.rb
is shown when rubygems is enabled.Tasks:
I will abide by the code of conduct.