Skip to content

Commit 35f852d

Browse files
committed
Ruby 2.7: Kernel#lambda with no block in a method called with a block raises an exception.
1 parent 5fd2b6b commit 35f852d

File tree

3 files changed

+3
-42
lines changed

3 files changed

+3
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Compatibility:
2525
* Add warning for `proc` without block (#2004, @ssnickolay).
2626
* Implemented `FrozenError#receiver`.
2727
* `Proc#<<` and `Proc#>>` raises TypeError if passed not callable object (#2004, @ssnickolay).
28+
* `Kernel#lambda` with no block in a method called with a block raises an exception (#2004, @ssnickolay).
2829

2930
Performance:
3031

spec/tags/language/lambda_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
fails:A lambda literal -> () { } assigns variables from parameters with circular optional argument reference raises a SyntaxError if using an existing local with the same name as the argument
22
fails:A lambda literal -> () { } assigns variables from parameters with circular optional argument reference raises a SyntaxError if there is an existing method with the same name as the argument
3-
fails:A lambda expression 'lambda { ... }' with an implicit block raises ArgumentError

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
import org.truffleruby.language.RubyRootNode;
9797
import org.truffleruby.language.RubySourceNode;
9898
import org.truffleruby.language.Visibility;
99-
import org.truffleruby.language.WarnNode;
10099
import org.truffleruby.language.WarningNode;
101100
import org.truffleruby.language.arguments.ReadCallerFrameNode;
102101
import org.truffleruby.language.arguments.RubyArguments;
@@ -148,7 +147,6 @@
148147
import com.oracle.truffle.api.dsl.ReportPolymorphism;
149148
import com.oracle.truffle.api.dsl.Specialization;
150149
import com.oracle.truffle.api.frame.FrameDescriptor;
151-
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
152150
import com.oracle.truffle.api.frame.FrameSlot;
153151
import com.oracle.truffle.api.frame.MaterializedFrame;
154152
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -1191,33 +1189,9 @@ protected boolean isATypeError(Object self, Object module) {
11911189
@CoreMethod(names = "lambda", isModuleFunction = true, needsBlock = true)
11921190
public abstract static class LambdaNode extends CoreMethodArrayArgumentsNode {
11931191

1194-
@Child private WarnNode warnNode;
1195-
1196-
@TruffleBoundary
11971192
@Specialization
1198-
protected RubyProc lambda(NotProvided block,
1199-
@Cached FindAndReadDeclarationVariableNode readNode) {
1200-
final MaterializedFrame parentFrame = getContext()
1201-
.getCallStack()
1202-
.getCallerFrameIgnoringSend(FrameAccess.MATERIALIZE)
1203-
.materialize();
1204-
Object parentBlock = readNode
1205-
.execute(parentFrame, TranslatorEnvironment.METHOD_BLOCK_NAME, nil);
1206-
1207-
if (parentBlock == nil) {
1208-
throw new RaiseException(
1209-
getContext(),
1210-
coreExceptions().argumentError("tried to create Proc object without a block", this));
1211-
} else {
1212-
warnProcWithoutBlock();
1213-
}
1214-
1215-
Node callNode = getContext().getCallStack().getCallerNode(2, true);
1216-
if (isLiteralBlock(callNode)) {
1217-
return lambdaFromBlock((RubyProc) parentBlock);
1218-
} else {
1219-
return (RubyProc) parentBlock;
1220-
}
1193+
protected RubyProc lambda(NotProvided block) {
1194+
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
12211195
}
12221196

12231197
@Specialization(guards = "isLiteralBlock(block)")
@@ -1240,19 +1214,6 @@ private boolean isLiteralBlock(Node callNode) {
12401214
RubyCallNode rubyCallNode = NodeUtil.findParent(callNode, RubyCallNode.class);
12411215
return rubyCallNode != null && rubyCallNode.hasLiteralBlock();
12421216
}
1243-
1244-
private void warnProcWithoutBlock() {
1245-
if (warnNode == null) {
1246-
CompilerDirectives.transferToInterpreterAndInvalidate();
1247-
warnNode = insert(new WarnNode());
1248-
}
1249-
1250-
if (warnNode.shouldWarn()) {
1251-
final SourceSection sourceSection = getContext().getCallStack().getTopMostUserSourceSection();
1252-
warnNode.warningMessage(sourceSection, "tried to create Proc object without a block");
1253-
}
1254-
}
1255-
12561217
}
12571218

12581219
@CoreMethod(names = "__method__", isModuleFunction = true)

0 commit comments

Comments
 (0)