27
27
import org .truffleruby .core .symbol .SymbolNodes ;
28
28
import org .truffleruby .language .NotProvided ;
29
29
import org .truffleruby .language .Visibility ;
30
+ import org .truffleruby .language .WarnNode ;
30
31
import org .truffleruby .language .arguments .ArgumentDescriptorUtils ;
31
32
import org .truffleruby .language .arguments .ReadCallerFrameNode ;
32
33
import org .truffleruby .language .arguments .RubyArguments ;
@@ -62,7 +63,6 @@ protected RubyProc allocate(RubyClass rubyClass) {
62
63
63
64
@ CoreMethod (names = "new" , constructor = true , needsBlock = true , rest = true )
64
65
public abstract static class ProcNewNode extends CoreMethodArrayArgumentsNode {
65
-
66
66
public static ProcNewNode create () {
67
67
return ProcNodesFactory .ProcNewNodeFactory .create (null );
68
68
}
@@ -73,14 +73,21 @@ public static ProcNewNode create() {
73
73
protected RubyProc proc (VirtualFrame frame , RubyClass procClass , Object [] args , NotProvided block ,
74
74
@ Cached FindAndReadDeclarationVariableNode readNode ,
75
75
@ Cached ReadCallerFrameNode readCaller ,
76
- @ Cached ProcNewNode recurseNode ) {
76
+ @ Cached ProcNewNode recurseNode ,
77
+ @ Cached ("new()" ) WarnNode warnNode ) {
77
78
final MaterializedFrame parentFrame = readCaller .execute (frame );
78
79
79
80
Object parentBlock = readNode .execute (parentFrame , TranslatorEnvironment .METHOD_BLOCK_NAME , nil );
80
81
81
82
if (parentBlock == nil ) {
82
83
throw new RaiseException (getContext (), coreExceptions ().argumentErrorProcWithoutBlock (this ));
83
84
} 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
+
84
91
final RubyProc proc = (RubyProc ) parentBlock ;
85
92
return recurseNode .executeProcNew (frame , procClass , args , proc );
86
93
}
0 commit comments