Skip to content

Commit f36bcec

Browse files
committed
Ensure InternalMethod#capturedBlock is always nil or a RubyProc
1 parent 0973f2c commit f36bcec

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/main/java/org/truffleruby/language/methods/InternalMethod.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.truffleruby.core.module.RubyModule;
2020
import org.truffleruby.core.proc.RubyProc;
2121
import org.truffleruby.language.LexicalScope;
22+
import org.truffleruby.language.Nil;
2223
import org.truffleruby.language.Visibility;
2324
import org.truffleruby.language.objects.ObjectGraphNode;
2425

@@ -94,7 +95,7 @@ public InternalMethod(
9495
null,
9596
callTarget,
9697
null,
97-
null);
98+
Nil.INSTANCE);
9899
}
99100

100101
public InternalMethod(
@@ -119,7 +120,7 @@ public InternalMethod(
119120
null,
120121
callTarget,
121122
callTargetSupplier,
122-
null);
123+
Nil.INSTANCE);
123124
}
124125

125126
public InternalMethod(
@@ -170,6 +171,7 @@ private InternalMethod(
170171
assert declaringModule != null;
171172
assert lexicalScope != null;
172173
assert !sharedMethodInfo.isBlock() : sharedMethodInfo;
174+
assert capturedBlock instanceof Nil || capturedBlock instanceof RubyProc : capturedBlock;
173175
this.sharedMethodInfo = sharedMethodInfo;
174176
this.lexicalScope = lexicalScope;
175177
this.declarationContext = declarationContext;

src/main/java/org/truffleruby/language/methods/LiteralMethodDefinitionNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.truffle.api.instrumentation.Tag;
1515
import org.truffleruby.collections.CachedSupplier;
1616
import org.truffleruby.core.module.RubyModule;
17+
import org.truffleruby.language.Nil;
1718
import org.truffleruby.language.RubyContextSourceNode;
1819
import org.truffleruby.language.RubyNode;
1920
import org.truffleruby.language.Visibility;
@@ -83,7 +84,7 @@ public Object execute(VirtualFrame frame) {
8384
null,
8485
null,
8586
callTargetSupplier,
86-
null);
87+
Nil.INSTANCE);
8788

8889
addMethodNode.executeAddMethod(module, method, visibility);
8990

src/main/java/org/truffleruby/language/methods/ModuleBodyDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public InternalMethod createMethod(VirtualFrame frame, LexicalScope staticLexica
5353
if (captureBlock) {
5454
capturedBlock = RubyArguments.getBlock(frame);
5555
} else {
56-
capturedBlock = null;
56+
capturedBlock = nil;
5757
}
5858

5959
final LexicalScope parentLexicalScope = RubyArguments.getMethod(frame).getLexicalScope();

src/main/java/org/truffleruby/language/yield/YieldExpressionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final Object execute(VirtualFrame frame) {
7070

7171
block = RubyArguments.getMethod(frame).getCapturedBlock();
7272

73-
if (block == null) {
73+
if (block == nil) {
7474
noCapturedBlock.enter();
7575
throw new RaiseException(getContext(), coreExceptions().noBlockToYieldTo(this));
7676
}

0 commit comments

Comments
 (0)