Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2951c362ff83
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 482c35a362fe
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Feb 16, 2016

  1. Copy the full SHA
    c460290 View commit details
  2. make sure auto-load does set-up parent module and name (see #3645)

    ... previously this worked as a side effect of fetchConstant "loading" auto-loads
    but since (b216c5d) `autoload` has been fixed to not initialize prematurely
    kares committed Feb 16, 2016
    Copy the full SHA
    538fc48 View commit details
  3. set parent module and name early on even for auto-load (closing #3645)

    ... this is not crucial but restores the same behavior as in JRuby < 9.0.5.0
    kares committed Feb 16, 2016
    Copy the full SHA
    482c35a View commit details
Showing with 43 additions and 14 deletions.
  1. +12 −14 core/src/main/java/org/jruby/RubyModule.java
  2. +6 −0 spec/regression/GH-3645_autoload.rb
  3. +25 −0 spec/regression/GH-3645_set_non_anonymous_constant.rb
26 changes: 12 additions & 14 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -3649,21 +3649,21 @@ public IRubyObject setConstant(String name, IRubyObject value, boolean hidden) {
*/
private IRubyObject setConstantCommon(String name, IRubyObject value, boolean hidden, boolean warn) {
IRubyObject oldValue = fetchConstant(name);

setParentForModule(name, value);

if (oldValue != null) {
if (oldValue == UNDEF) {
setAutoloadConstant(name, value);
} else {
if (warn) {
boolean notAutoload = oldValue != UNDEF;
if (notAutoload || !setAutoloadConstant(name, value)) {
if (warn && notAutoload) {
getRuntime().getWarnings().warn(ID.CONSTANT_ALREADY_INITIALIZED, "already initialized constant " + name);
}
setParentForModule(name, value);
// might just call storeConstant(name, value, hidden) but to maintain
// backwards compatibility with calling #storeConstant overrides
if (hidden) storeConstant(name, value, true);
else storeConstant(name, value);
}
} else {
setParentForModule(name, value);
if (hidden) storeConstant(name, value, true);
else storeConstant(name, value);
}
@@ -4148,6 +4148,7 @@ protected final IRubyObject finishAutoload(String name) {
storeConstant(name, value);
}
removeAutoload(name);
invalidateConstantCache(name);
return value;
}

@@ -4170,17 +4171,14 @@ protected IRubyObject getAutoloadConstant(String name, boolean loadConstant) {
/**
* Set an Object as a defined constant in autoloading.
*/
private void setAutoloadConstant(String name, IRubyObject value) {
private boolean setAutoloadConstant(String name, IRubyObject value) {
final Autoload autoload = getAutoloadMap().get(name);
if ( autoload != null ) {
if ( ! autoload.setConstant(getRuntime().getCurrentContext(), value) ) {
storeConstant(name, value);
removeAutoload(name);
}
}
else {
storeConstant(name, value);
boolean set = autoload.setConstant(getRuntime().getCurrentContext(), value);
if ( ! set ) removeAutoload(name);
return set;
}
return false;
}

/**
6 changes: 6 additions & 0 deletions spec/regression/GH-3645_autoload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GH3645.add_mod(:S3)

module GH3645
module S3
end
end
25 changes: 25 additions & 0 deletions spec/regression/GH-3645_set_non_anonymous_constant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module GH3645
class << self

def add_mod(name) # call this from autoloaded script
mod = Module.new { extend GH3645 }
const_set(name, mod)
mod
end

end
autoload :S3, File.expand_path('GH-3645_autoload', File.dirname(__FILE__))
end

describe 'GH-3645' do

it 'sets a constant' do
GH3645.add_mod :A_MODULE
expect( GH3645::A_MODULE.name ).to eql 'GH3645::A_MODULE'
end

it 'sets an auto-loaded constant' do
expect( GH3645::S3.name ).to eql 'GH3645::S3'
end

end