Skip to content

Commit 90d2f50

Browse files
committed
Fix TODO in Module#define_method(UnboundMethod)
1 parent 0bb2154 commit 90d2f50

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,11 +1052,14 @@ public DynamicObject defineMethod(DynamicObject module, String name, DynamicObje
10521052
final InternalMethod internalMethod = Layouts.UNBOUND_METHOD.getMethod(method);
10531053
if (!ModuleOperations.canBindMethodTo(internalMethod, module)) {
10541054
final DynamicObject declaringModule = internalMethod.getDeclaringModule();
1055-
throw new RaiseException(getContext(), coreExceptions().typeError("bind argument must be a subclass of " + Layouts.MODULE.getFields(declaringModule).getName(), this));
1055+
if (RubyGuards.isSingletonClass(declaringModule)) {
1056+
throw new RaiseException(getContext(), coreExceptions().typeError(
1057+
"can't bind singleton method to a different class", this));
1058+
} else {
1059+
throw new RaiseException(getContext(), coreExceptions().typeError("bind argument must be a subclass of " + Layouts.MODULE.getFields(declaringModule).getName(), this));
1060+
}
10561061
}
10571062

1058-
// TODO CS 5-Apr-15 TypeError if the method came from a singleton
1059-
10601063
return addMethod(module, name, internalMethod);
10611064
}
10621065

0 commit comments

Comments
 (0)