Skip to content

Commit 8e52290

Browse files
committed
[GR-18163] Ruby 2.7: Add warning for proc without block (#2162)
PullRequest: truffleruby/2172
2 parents d0d9015 + 696372a commit 8e52290

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Compatibility:
2121
* Pass more `Enumerator::Lazy#uniq` and `Enumerator::Lazy#chunk` specs (#2146, @LillianZ).
2222
* Implement `Enumerator#produce` (#2160, @zverok)
2323
* Implement `Complex#<=>` (#2004, @ssnickolay).
24+
* Add warning for `proc` without block (#2004, @ssnickolay).
2425

2526
Performance:
2627

spec/tags/core/kernel/proc_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.truffleruby.core.symbol.SymbolNodes;
2828
import org.truffleruby.language.NotProvided;
2929
import org.truffleruby.language.Visibility;
30+
import org.truffleruby.language.WarnNode;
3031
import org.truffleruby.language.arguments.ArgumentDescriptorUtils;
3132
import org.truffleruby.language.arguments.ReadCallerFrameNode;
3233
import org.truffleruby.language.arguments.RubyArguments;
@@ -62,7 +63,6 @@ protected RubyProc allocate(RubyClass rubyClass) {
6263

6364
@CoreMethod(names = "new", constructor = true, needsBlock = true, rest = true)
6465
public abstract static class ProcNewNode extends CoreMethodArrayArgumentsNode {
65-
6666
public static ProcNewNode create() {
6767
return ProcNodesFactory.ProcNewNodeFactory.create(null);
6868
}
@@ -73,14 +73,21 @@ public static ProcNewNode create() {
7373
protected RubyProc proc(VirtualFrame frame, RubyClass procClass, Object[] args, NotProvided block,
7474
@Cached FindAndReadDeclarationVariableNode readNode,
7575
@Cached ReadCallerFrameNode readCaller,
76-
@Cached ProcNewNode recurseNode) {
76+
@Cached ProcNewNode recurseNode,
77+
@Cached("new()") WarnNode warnNode) {
7778
final MaterializedFrame parentFrame = readCaller.execute(frame);
7879

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

8182
if (parentBlock == nil) {
8283
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
8384
} else {
85+
if (warnNode.shouldWarn()) {
86+
warnNode.warningMessage(
87+
getContext().getCallStack().getTopMostUserSourceSection(),
88+
"Capturing the given block using Kernel#proc is deprecated; use `&block` instead");
89+
}
90+
8491
final RubyProc proc = (RubyProc) parentBlock;
8592
return recurseNode.executeProcNew(frame, procClass, args, proc);
8693
}

test/mri/excludes/TestProc.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
exclude :test_proc_args_pos_rest_post_block, "needs investigation"
2626
exclude :test_proc_args_rest_post, "needs investigation"
2727
exclude :test_proc_args_rest_post_block, "needs investigation"
28-
exclude :test_proc_without_block_for_symbol, "needs investigation"
2928
exclude :test_safe, "needs investigation"
3029
exclude :test_compose_with_noncallable, "needs investigation"
3130
exclude :test_orphan_return, "needs investigation"

0 commit comments

Comments
 (0)