Skip to content

Commit 2c13270

Browse files
committedNov 27, 2014
Fix broken method chains on methods donated by modules
1 parent e31438b commit 2c13270

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

‎opal/corelib/runtime.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,23 @@
935935
}
936936
else if (dest.hasOwnProperty(jsid) && !current.$$stub) {
937937
// target class includes another module that has defined this method
938-
// FIXME: we should resolve the order of modules to check if we
939-
// should define it
940-
dest[jsid] = body;
941-
dest[jsid].$$donated = true;
938+
var klass_includees = includee.$$inc;
939+
940+
for (var j = 0, jj = klass_includees.length; j < jj; j++) {
941+
if (klass_includees[j] === current.$$owner) {
942+
var current_owner_index = j;
943+
}
944+
if (klass_includees[j] === module) {
945+
var module_index = j;
946+
}
947+
}
948+
949+
// only redefine method on class if the module was included AFTER
950+
// the module which defined the current method body
951+
if (current_owner_index < module_index) {
952+
dest[jsid] = body;
953+
dest[jsid].$$donated = true;
954+
}
942955
}
943956
else {
944957
// neither a class, or module included by class, has defined method

‎spec/filters/bugs/module.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
fails "Module#module_function with specific method names can make accessible private methods"
2525
fails "Module#module_function as a toggle (no arguments) in a Module body does not affect module_evaled method definitions also if outside the eval itself"
2626
fails "Module#module_function as a toggle (no arguments) in a Module body has no effect if inside a module_eval if the definitions are outside of it"
27+
fails "Module#module_function with specific method names creates an independent copy of the method, not a redirect"
2728
end

0 commit comments

Comments
 (0)
Please sign in to comment.