Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public boolean isNestedClosuresSafeForMethodConversion() {
public IRMethod convertToMethod(ByteList name) {
// We want variable scoping to be the same as a method and not see outside itself.
if (source == null ||
isWithinMethod() || // def foo; define_method {}; end has potential to implicitly access parents var yield
accessesParentsLocalVariables() || // Built methods cannot search down past method scope
receivesClosureArg() || // we pass in captured block at define_method as block so explicits ones not supported
usesZSuper() || // methods defined from closures cannot use zsuper
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ public boolean isWithinEND() {
return false;
}

public boolean isWithinMethod() {
for (IRScope current = this; current != null; current = current.getLexicalParent()) {
if (current instanceof IRModuleBody) return false;
if (current instanceof IRMethod) return true;
}

return false;
}

// walks up closures
public IRScope getNearestNonClosurelikeScope() {
IRScope current = this;
Expand Down