Skip to content

Commit

Permalink
Ruby 2.7: Add warning for proc without block
Browse files Browse the repository at this point in the history
  • Loading branch information
ssnickolay committed Nov 17, 2020
1 parent 001f1dc commit 696372a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Compatibility:
* Implement `Enumerable#tally` and `Enumerable#filter_map` (#2144 and #2152, @LillianZ).
* Implement `Range#minmax`.
* Pass more `Enumerator::Lazy#uniq` and `Enumerator::Lazy#chunk` specs (#2146, @LillianZ).
* Add warning for `proc` without block (#2004, @ssnickolay).

Performance:

Expand Down
1 change: 0 additions & 1 deletion spec/tags/core/kernel/proc_tags.txt

This file was deleted.

11 changes: 9 additions & 2 deletions src/main/java/org/truffleruby/core/proc/ProcNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.truffleruby.core.symbol.SymbolNodes;
import org.truffleruby.language.NotProvided;
import org.truffleruby.language.Visibility;
import org.truffleruby.language.WarnNode;
import org.truffleruby.language.arguments.ArgumentDescriptorUtils;
import org.truffleruby.language.arguments.ReadCallerFrameNode;
import org.truffleruby.language.arguments.RubyArguments;
Expand Down Expand Up @@ -62,7 +63,6 @@ protected RubyProc allocate(RubyClass rubyClass) {

@CoreMethod(names = "new", constructor = true, needsBlock = true, rest = true)
public abstract static class ProcNewNode extends CoreMethodArrayArgumentsNode {

public static ProcNewNode create() {
return ProcNodesFactory.ProcNewNodeFactory.create(null);
}
Expand All @@ -73,14 +73,21 @@ public static ProcNewNode create() {
protected RubyProc proc(VirtualFrame frame, RubyClass procClass, Object[] args, NotProvided block,
@Cached FindAndReadDeclarationVariableNode readNode,
@Cached ReadCallerFrameNode readCaller,
@Cached ProcNewNode recurseNode) {
@Cached ProcNewNode recurseNode,
@Cached("new()") WarnNode warnNode) {
final MaterializedFrame parentFrame = readCaller.execute(frame);

Object parentBlock = readNode.execute(parentFrame, TranslatorEnvironment.METHOD_BLOCK_NAME, nil);

if (parentBlock == nil) {
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
} else {
if (warnNode.shouldWarn()) {
warnNode.warningMessage(
getContext().getCallStack().getTopMostUserSourceSection(),
"Capturing the given block using Kernel#proc is deprecated; use `&block` instead");
}

final RubyProc proc = (RubyProc) parentBlock;
return recurseNode.executeProcNew(frame, procClass, args, proc);
}
Expand Down
1 change: 0 additions & 1 deletion test/mri/excludes/TestProc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
exclude :test_proc_args_pos_rest_post_block, "needs investigation"
exclude :test_proc_args_rest_post, "needs investigation"
exclude :test_proc_args_rest_post_block, "needs investigation"
exclude :test_proc_without_block_for_symbol, "needs investigation"
exclude :test_safe, "needs investigation"
exclude :test_compose_with_noncallable, "needs investigation"
exclude :test_orphan_return, "needs investigation"
Expand Down

0 comments on commit 696372a

Please sign in to comment.