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: 001d36ae59f3
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd741c614bb6
Choose a head ref
  • 4 commits
  • 11 files changed
  • 1 contributor

Commits on Oct 2, 2015

  1. Copy the full SHA
    cbef104 View commit details
  2. Copy the full SHA
    e6caf01 View commit details
  3. Copy the full SHA
    eb0b7b9 View commit details
  4. Add tags for new specs.

    eregon committed Oct 2, 2015
    Copy the full SHA
    bd741c6 View commit details
37 changes: 37 additions & 0 deletions spec/ruby/language/def_spec.rb
Original file line number Diff line number Diff line change
@@ -475,6 +475,43 @@ def a_singleton_method;self;end
lambda { other.a_singleton_method }.should raise_error(NoMethodError)
end

it "creates a method in the surrounding context when evaluated in a def expr.method" do
class DefSpecNested
TARGET = Object.new
def TARGET.defs_method
def inherited_method;self;end
end
end

DefSpecNested::TARGET.defs_method
DefSpecNested.should have_instance_method :inherited_method
DefSpecNested::TARGET.should_not have_method :inherited_method

obj = DefSpecNested.new
obj.inherited_method.should == obj
end

# See http://yugui.jp/articles/846#label-3
it "inside an instance_eval creates a singleton method" do
class DefSpecNested
OBJ = Object.new
OBJ.instance_eval do
def create_method_in_instance_eval(a = (def arg_method; end))
def body_method; end
end
end
end

obj = DefSpecNested::OBJ
obj.create_method_in_instance_eval

obj.should have_method :arg_method
obj.should have_method :body_method

DefSpecNested.should_not have_instance_method :arg_method
DefSpecNested.should_not have_instance_method :body_method
end

it "defines methods as public by default" do
cls = Class.new do
def do_def
1 change: 1 addition & 0 deletions spec/tags/ruby/language/def_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fails:An instance method with a default argument does not call a method with the same name as the local
fails:An instance method with a default argument shadows an existing method with the same name as the local
fails:A nested method definition creates a method in the surrounding context when evaluated in a def expr.method
1 change: 1 addition & 0 deletions spec/truffle/tags/language/def_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fails:An instance method with a default argument does not call a method with the same name as the local
fails:An instance method with a default argument shadows an existing method with the same name as the local
fails:A nested method definition inside an instance_eval creates a singleton method
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public void addCoreMethodNodes(List<? extends NodeFactory<? extends RubyNode>> n
}

private DynamicObject getSingletonClass(Object object) {
return singletonClassNode.executeSingletonClass(null, object);
return singletonClassNode.executeSingletonClass(object);
}

private void addCoreMethod(MethodDetails methodDetails) {
Original file line number Diff line number Diff line change
@@ -454,7 +454,7 @@ public DynamicObject clone(VirtualFrame frame, DynamicObject self) {

// Copy the singleton class if any.
if (Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(self))) {
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(frame, newObject)).initCopy(Layouts.BASIC_OBJECT.getMetaClass(self));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(newObject)).initCopy(Layouts.BASIC_OBJECT.getMetaClass(self));
}

initializeCloneNode.call(frame, newObject, "initialize_clone", null, self);
@@ -1770,8 +1770,8 @@ public SingletonClassMethodNode(RubyContext context, SourceSection sourceSection
}

@Specialization
public DynamicObject singletonClass(VirtualFrame frame, Object self) {
return singletonClassNode.executeSingletonClass(frame, self);
public DynamicObject singletonClass(Object self) {
return singletonClassNode.executeSingletonClass(self);
}

}
Original file line number Diff line number Diff line change
@@ -1139,13 +1139,13 @@ public ExtendObjectNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public DynamicObject extendObject(VirtualFrame frame, DynamicObject module, DynamicObject object) {
public DynamicObject extendObject(DynamicObject module, DynamicObject object) {
if (RubyGuards.isRubyClass(module)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorWrongArgumentType(module, "Module", this));
}

Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(frame, object)).include(this, module);
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).include(this, module);
return module;
}

@@ -1394,7 +1394,7 @@ public PublicClassMethodNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public DynamicObject publicClassMethod(VirtualFrame frame, DynamicObject module, Object[] names) {
final DynamicObject singletonClass = singletonClassNode.executeSingletonClass(frame, module);
final DynamicObject singletonClass = singletonClassNode.executeSingletonClass(module);

for (Object name : names) {
setMethodVisibilityNode.executeSetMethodVisibility(frame, singletonClass, name);
@@ -1459,7 +1459,7 @@ public PrivateClassMethodNode(RubyContext context, SourceSection sourceSection)

@Specialization
public DynamicObject privateClassMethod(VirtualFrame frame, DynamicObject module, Object[] names) {
final DynamicObject singletonClass = singletonClassNode.executeSingletonClass(frame, module);
final DynamicObject singletonClass = singletonClassNode.executeSingletonClass(module);

for (Object name : names) {
setMethodVisibilityNode.executeSetMethodVisibility(frame, singletonClass, name);
@@ -1986,7 +1986,7 @@ public DynamicObject setMethodVisibility(VirtualFrame frame, DynamicObject modul
*/
if (visibility == Visibility.MODULE_FUNCTION) {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(frame, module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
} else {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(visibility));
}
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ public DynamicObject execute(VirtualFrame frame) {

if (method.getVisibility() == Visibility.MODULE_FUNCTION) {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(frame, module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
} else {
Layouts.MODULE.getFields(module).addMethod(this, method);
}
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@ public Object alias(DynamicObject module) {

// TODO (eregon, 10 May 2015): we should only have the module case as the child should be the default definee
@Specialization(guards = "!isRubyModule(object)")
public Object alias(VirtualFrame frame, Object object) {
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(frame, object)).alias(this, newName, oldName);
public Object alias(Object object) {
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).alias(this, newName, oldName);
return object;
}

Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public DynamicObject getModuleToDefineMethods(VirtualFrame frame, RubyContext co
return RubyArguments.getMethod(frame.getArguments()).getSharedMethodInfo().getLexicalScope().getLiveModule();
case SINGLETON_CLASS:
final Object self = RubyArguments.getSelf(frame.getArguments());
return singletonClassNode.executeSingletonClass(frame, self);
return singletonClassNode.executeSingletonClass(self);
case SELF:
return (DynamicObject) RubyArguments.getSelf(frame.getArguments());
default:
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public SingletonClassNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public abstract DynamicObject executeSingletonClass(VirtualFrame frame, Object value);
public abstract DynamicObject executeSingletonClass(Object value);

@Specialization(guards = "value")
protected DynamicObject singletonClassTrue(boolean value) {
Original file line number Diff line number Diff line change
@@ -255,8 +255,8 @@ public VMObjectSingletonClassPrimitiveNode(RubyContext context, SourceSection so
}

@Specialization
public Object vmObjectClass(VirtualFrame frame, Object object) {
return singletonClassNode.singletonClass(frame, object);
public Object vmObjectClass(Object object) {
return singletonClassNode.singletonClass(object);
}

}