Skip to content

Commit 9ea9234

Browse files
committed
Partially make forwarding across evals work. This fixed * and ** but ... is done differently so not in this commit
1 parent 5db2201 commit 9ea9234

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/main/java/org/jruby/prism/builder/IRBuilderPrism.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,12 @@ protected Operand[] buildCallArgsArray(Node[] children, int[] flags) {
704704
flags[0] |= CALL_SPLATS;
705705
builtArgs[i] = new Splat(addResultInstr(new BuildSplatInstr(temp(), build(splat), true)));
706706
} else {
707-
builtArgs[i] = new Splat(scope.lookupExistingLVar(symbol("*")));
707+
// Note: WOOF. Prism forwarding returns '*' as an expressless splat instead of a splat
708+
// of a lvar named '*'. IRScope cannot give us the power to search assuming this is all
709+
// going to be handed to it by the parser so we need to look it up in StaticScope.
710+
var slot = scope.getStaticScope().isDefined("*");
711+
var lvar = new LocalVariable(symbol("*"), slot >> 16, slot & 0xffff, true);
712+
builtArgs[i] = new Splat(lvar);
708713
}
709714
} else if (child instanceof KeywordHashNode hash && i == numberOfArgs - 1) {
710715
builtArgs[i] = buildCallKeywordArguments(hash, flags); // FIXME: here and possibly AST make isKeywordsHash() method.
@@ -1885,8 +1890,12 @@ private Operand buildRestKeywordArgs(KeywordHashNode keywordArgs, int[] flags) {
18851890
var pair = (AssocSplatNode) pairs[0];
18861891

18871892
if (pair.value == null) {
1888-
return scope.lookupExistingLVar(symbol("**"));
1889-
} else {
1893+
// Note: WOOF. Prism forwarding returns '**' as an expressless splat instead of a splat
1894+
// of a lvar named '**'. IRScope cannot give us the power to search assuming this is all
1895+
// going to be handed to it by the parser so we need to look it up in StaticScope.
1896+
var slot = scope.getStaticScope().isDefined("**");
1897+
return new LocalVariable(symbol("**"), slot >> 16, slot & 0xffff, true);
1898+
} else {
18901899
Operand splat = buildWithOrder(pair.value, containsVariableAssignment);
18911900

18921901
return addResultInstr(new RuntimeHelperCall(temp(), HASH_CHECK, new Operand[]{splat}));

src/main/java/org/jruby/prism/parser/ParserPrismBase.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.jruby.RubyArray;
88
import org.jruby.RubyFile;
99
import org.jruby.RubyInstanceConfig;
10-
import org.jruby.RubySymbol;
1110
import org.jruby.ext.coverage.CoverageData;
1211
import org.jruby.management.ParserStats;
1312
import org.jruby.parser.Parser;
@@ -199,14 +198,25 @@ private void evalScopesRecursive(StaticScope scope, ArrayList<ParsingOptions.Sco
199198
evalScopesRecursive(scope.getEnclosingScope(), scopes);
200199
}
201200

201+
var variables = scope.getVariables();
202+
202203
scopes.add(new ParsingOptions.Scope(
203204
Arrays
204-
.stream(scope.getVariables())
205+
.stream(variables)
205206
.map(String::getBytes)
206207
.toArray(byte[][]::new),
207208
IntStream
208209
.range(0, scope.getVariables().length)
209-
.mapToObj((i) -> ParsingOptions.Forwarding.NONE)
210+
.mapToObj((i) -> {
211+
var name = variables[i];
212+
return switch (name) {
213+
case "..." -> ParsingOptions.Forwarding.ALL;
214+
case "*" -> ParsingOptions.Forwarding.POSITIONAL;
215+
case "**" -> ParsingOptions.Forwarding.KEYWORD;
216+
case "&" -> ParsingOptions.Forwarding.BLOCK;
217+
default -> ParsingOptions.Forwarding.NONE;
218+
};
219+
})
210220
.toArray(ParsingOptions.Forwarding[]::new)));
211221
}
212222

0 commit comments

Comments
 (0)