// 2. If not, and if the closure is ultimately nested within a method, build a local variable that will
// be defined in that method.
// 3. If not, and if the closure is not nested within a method, the closure can never receive a block.
// So, we could return 'null', but it creates problems for IR generation. So, for this scenario,
// we simply create a dummy var at depth 0 (meaning, it is local to the closure itself) and return it.
LocalVariable blockVar = findExistingLocalVariable(Variable.BLOCK, getNestingDepth());
if (blockVar != null) {
// Create a copy of the variable usable at the right depth
if (blockVar.getScopeDepth() != getNestingDepth()) blockVar = blockVar.cloneForDepth(getNestingDepth());
} else {
IRScope s = this;
while (s instanceof IRClosure) s = s.getLexicalParent();
if (s instanceof IRMethod) {
blockVar = s.getNewLocalVariable(Variable.BLOCK, 0);
// Create a copy of the variable usable at the right depth
if (getNestingDepth() != 0) blockVar = blockVar.cloneForDepth(getNestingDepth());
} else {
// Dummy var
blockVar = getNewLocalVariable(Variable.BLOCK, 0);
}
}