Skip to content

Commit 8c0f074

Browse files
committed
Fix ArgumentType for anonymous keyword rest arguments
1 parent 83803b1 commit 8c0f074

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

spec/truffle/parsing/fixtures/block/argument_descriptors/with_double_splat_operator_without_name.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ast: |
1919
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = org.truffleruby.parser.MethodTranslator$$Lambda$.../0x...@...)
2020
flags = 0
2121
frameOnStackMarkerSlot = 2
22-
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 1], index=0, length=20, characters=proc do |a:, b:, **|), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = keyrest)])
22+
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 1], index=0, length=20, characters=proc do |a:, b:, **|), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = anonkeyrest)])
2323
type = PROC
2424
call targets:
2525
RubyProcRootNode
@@ -33,7 +33,7 @@ ast: |
3333
redoProfile = false
3434
retryProfile = false
3535
returnID = org.truffleruby.language.control.ReturnID@...
36-
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 1], index=0, length=20, characters=proc do |a:, b:, **|), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = keyrest)])
36+
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 1], index=0, length=20, characters=proc do |a:, b:, **|), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = anonkeyrest)])
3737
sourceSection = SourceSection(source=<parse_ast> [1 - 1], index=0, length=20, characters=proc do |a:, b:, **|)
3838
split = HEURISTIC
3939
children:

spec/truffle/parsing/fixtures/def/argument_descriptors/with_double_splat_operator_without_name.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ notes: >
44
Method parameters are described (as ArgumentDescriptor[]) in the following way:
55
- ArgumentDescriptor(name = a, type = keyreq)
66
- ArgumentDescriptor(name = b, type = keyreq)
7-
- ArgumentDescriptor(name = %kwrest, type = keyrest)
7+
- ArgumentDescriptor(name = %kwrest, type = anonkeyrest)
88
9-
So the rest keyword arguments are described as a `keyrest` variable with surrogate name `%kwrest`.
10-
# TODO: why not anonrest?
9+
So the rest keyword arguments are described as a `anonkeyrest` variable with surrogate name `%kwrest`.
1110
focused_on_node: "org.truffleruby.language.methods.LiteralMethodDefinitionNode"
1211
ruby: |
1312
def foo(a:, b:, **)
@@ -19,7 +18,7 @@ ast: |
1918
flags = 1
2019
isDefSingleton = false
2120
name = "foo"
22-
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 2], index=0, length=23, characters=def foo(a:, b:, **)\nend), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = keyrest)])
21+
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 2], index=0, length=23, characters=def foo(a:, b:, **)\nend), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = anonkeyrest)])
2322
call targets:
2423
RubyMethodRootNode
2524
attributes:
@@ -36,7 +35,7 @@ ast: |
3635
polyglotRef = org.truffleruby.RubyLanguage@...
3736
retryProfile = false
3837
returnID = org.truffleruby.language.control.ReturnID@...
39-
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 2], index=0, length=23, characters=def foo(a:, b:, **)\nend), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = keyrest)])
38+
sharedMethodInfo = SharedMethodInfo(sourceSection = SourceSection(source=<parse_ast> [1 - 2], index=0, length=23, characters=def foo(a:, b:, **)\nend), staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = a, type = keyreq), ArgumentDescriptor(name = b, type = keyreq), ArgumentDescriptor(name = %kwrest, type = anonkeyrest)])
4039
sourceSection = SourceSection(source=<parse_ast> [1 - 2], index=0, length=23, characters=def foo(a:, b:, **)\nend)
4140
split = HEURISTIC
4241
children:

src/main/java/org/truffleruby/parser/Helpers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.truffleruby.parser.ast.RequiredKeywordArgumentValueParseNode;
4343
import org.truffleruby.parser.ast.UnnamedRestArgParseNode;
4444
import org.truffleruby.parser.ast.types.INameNode;
45+
import org.truffleruby.parser.parser.ParserSupport;
4546

4647
public final class Helpers {
4748

@@ -131,7 +132,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsParseNode a
131132

132133
if (argsNode.getKeyRest() != null) {
133134
String argName = argsNode.getKeyRest().getName();
134-
if (argName == null || argName.length() == 0) {
135+
if (argName == null || argName.length() == 0 || argName.equals(ParserSupport.KWREST_VAR)) {
135136
descs.add(new ArgumentDescriptor(ArgumentType.anonkeyrest, argName));
136137
} else {
137138
descs.add(new ArgumentDescriptor(ArgumentType.keyrest, argsNode.getKeyRest().getName()));

src/main/java/org/truffleruby/parser/parser/ParserSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public final class ParserSupport {
180180
.usAsciiString(FORWARD_ARGS_KWREST_VAR);
181181
/** The local variable to store the block from ... in */
182182
public static final String FORWARD_ARGS_BLOCK_VAR = Layouts.TEMP_PREFIX + "forward_block";
183+
public static final String KWREST_VAR = Layouts.TEMP_PREFIX + "kwrest";
183184
public static final TruffleString FORWARD_ARGS_BLOCK_VAR_TSTRING = TStringUtils
184185
.usAsciiString(FORWARD_ARGS_BLOCK_VAR);
185186
/** A prefix for duplicated '_' local variables to build unique names */
@@ -1571,7 +1572,7 @@ public ArgsTailHolder new_args_tail(SourceIndexLength position, ListParseNode ke
15711572

15721573
final String restKwargsName;
15731574
if (keywordRestArgName.isEmpty()) {
1574-
restKwargsName = Layouts.TEMP_PREFIX + "kwrest";
1575+
restKwargsName = KWREST_VAR;
15751576
} else {
15761577
restKwargsName = keywordRestArgName.toJavaStringUncached().intern();
15771578
}

0 commit comments

Comments
 (0)