Skip to content

Commit

Permalink
Add deprecation warning when Kernel#lambda is called without block li…
Browse files Browse the repository at this point in the history
…teral
  • Loading branch information
andrykonchin authored and eregon committed Oct 21, 2021
1 parent 1eb1984 commit 113acb1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/org/truffleruby/core/kernel/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,20 @@ protected RubyProc lambdaFromProcBlock(RubyProc block) {
return ProcOperations.createLambdaFromBlock(getContext(), getLanguage(), block);
}

@Specialization(guards = "!isLiteralBlock(block)")
@Specialization(guards = { "!isLiteralBlock(block)", "block.isProc()" })
protected RubyProc lambdaFromExistingProc(RubyProc block,
@Cached("new()") WarningNode warningNode) {
if (warningNode.shouldWarnForDeprecation()) {
warningNode.warningMessage(
getContext().getCallStack().getTopMostUserSourceSection(),
"lambda without a literal block is deprecated; use the proc without lambda instead");
}

// If the argument isn't a literal, its original behaviour (proc or lambda) is preserved.
return block;
}

@Specialization(guards = { "!isLiteralBlock(block)", "block.isLambda()" })
protected RubyProc lambdaFromExistingProc(RubyProc block) {
// If the argument isn't a literal, its original behaviour (proc or lambda) is preserved.
return block;
Expand Down

0 comments on commit 113acb1

Please sign in to comment.