Skip to content

Commit e361519

Browse files
committed
Raise ArgumentError uncoditionally when Proc.new is called without a block
1 parent f50bb4a commit e361519

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

spec/tags/core/proc/new_tags.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
fails:Proc.new with an associated block raises a LocalJumpError when context of the block no longer exists
2-
fails:Proc.new without a block can be created if invoked from within a method with a block
3-
fails:Proc.new without a block can be created if invoked on a subclass from within a method with a block
4-
fails:Proc.new without a block can be create when called with no block
5-
fails:Proc.new without a block raises an ArgumentError when passed no block

src/main/java/org/truffleruby/core/proc/ProcNodes.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@
3131
import org.truffleruby.core.symbol.SymbolNodes;
3232
import org.truffleruby.language.Nil;
3333
import org.truffleruby.language.Visibility;
34-
import org.truffleruby.language.WarnNode;
3534
import org.truffleruby.language.arguments.ArgumentDescriptorUtils;
36-
import org.truffleruby.language.arguments.ReadCallerFrameNode;
3735
import org.truffleruby.language.arguments.RubyArguments;
3836
import org.truffleruby.language.control.RaiseException;
3937
import org.truffleruby.language.dispatch.DispatchNode;
40-
import org.truffleruby.language.locals.FindDeclarationVariableNodes.FindAndReadDeclarationVariableNode;
4138
import org.truffleruby.language.methods.Arity;
4239
import org.truffleruby.language.objects.AllocationTracing;
4340
import org.truffleruby.language.objects.LogicalClassNode;
4441
import org.truffleruby.language.yield.CallBlockNode;
4542
import org.truffleruby.parser.ArgumentDescriptor;
46-
import org.truffleruby.parser.TranslatorEnvironment;
4743

4844
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4945
import com.oracle.truffle.api.dsl.Cached;
@@ -75,27 +71,8 @@ public static ProcNewNode create() {
7571
public abstract RubyProc executeProcNew(VirtualFrame frame, RubyClass procClass, Object[] args, Object block);
7672

7773
@Specialization
78-
protected RubyProc proc(VirtualFrame frame, RubyClass procClass, Object[] args, Nil block,
79-
@Cached FindAndReadDeclarationVariableNode readNode,
80-
@Cached ReadCallerFrameNode readCaller,
81-
@Cached ProcNewNode recurseNode,
82-
@Cached("new()") WarnNode warnNode) {
83-
final MaterializedFrame parentFrame = readCaller.execute(frame);
84-
85-
Object parentBlock = readNode.execute(parentFrame, TranslatorEnvironment.METHOD_BLOCK_NAME, nil);
86-
87-
if (parentBlock == nil) {
88-
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
89-
} else {
90-
if (warnNode.shouldWarnForDeprecation()) {
91-
warnNode.warningMessage(
92-
getContext().getCallStack().getTopMostUserSourceSection(),
93-
"Capturing the given block using Kernel#proc is deprecated; use `&block` instead");
94-
}
95-
96-
final RubyProc proc = (RubyProc) parentBlock;
97-
return recurseNode.executeProcNew(frame, procClass, args, proc);
98-
}
74+
protected RubyProc proc(VirtualFrame frame, RubyClass procClass, Object[] args, Nil block) {
75+
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
9976
}
10077

10178
@Specialization(guards = { "procClass == getProcClass()", "block.getShape() == getProcShape()" })

0 commit comments

Comments
 (0)