Skip to content

Commit 1a33569

Browse files
committed
Fix #parameters for **nil
1 parent b6f0f7f commit 1a33569

File tree

8 files changed

+18
-11
lines changed

8 files changed

+18
-11
lines changed

spec/ruby/core/method/parameters_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def one_key(a: 1); end
77
def one_keyrest(**a); end
88

99
def one_keyreq(a:); end
10+
def one_nokey(**nil); end
1011

1112
def one_splat_one_req(*a,b); end
1213
def one_splat_two_req(*a,b,c); end
@@ -178,6 +179,11 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
178179
m.parameters.should == [[:keyreq,:a]]
179180
end
180181

182+
it "returns [[:nokey]] for a method with a single **nil parameter" do
183+
m = MethodSpecs::Methods.instance_method(:one_nokey)
184+
m.parameters.should == [[:nokey]]
185+
end
186+
181187
it "works with ->(){} as the value of an optional argument" do
182188
m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby)
183189
m.parameters.should == [[:opt,:a]]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ast: |
1616
flags = 1
1717
isDefSingleton = false
1818
name = "foo"
19-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
19+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
2020
call targets:
2121
RubyMethodRootNode
2222
attributes:
@@ -33,7 +33,7 @@ ast: |
3333
polyglotRef = org.truffleruby.RubyLanguage@...
3434
retryProfile = false
3535
returnID = org.truffleruby.language.control.ReturnID@...
36-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
36+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
3737
split = HEURISTIC
3838
children:
3939
body =

spec/truffle/parsing/fixtures/def/arity/with_rejecting_keyword_arguments.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ast: |
2020
flags = 1
2121
isDefSingleton = false
2222
name = "foo"
23-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
23+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
2424
call targets:
2525
RubyMethodRootNode
2626
attributes:
@@ -37,7 +37,7 @@ ast: |
3737
polyglotRef = org.truffleruby.RubyLanguage@...
3838
retryProfile = false
3939
returnID = org.truffleruby.language.control.ReturnID@...
40-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
40+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
4141
split = HEURISTIC
4242
children:
4343
body =

spec/truffle/parsing/fixtures/def/parameters_to_local_variables/with_rejecting_keyword_arguments.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ast: |
1616
flags = 1
1717
isDefSingleton = false
1818
name = "foo"
19-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
19+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
2020
call targets:
2121
RubyMethodRootNode
2222
attributes:
@@ -33,7 +33,7 @@ ast: |
3333
polyglotRef = org.truffleruby.RubyLanguage@...
3434
retryProfile = false
3535
returnID = org.truffleruby.language.control.ReturnID@...
36-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = %nil_kwrest, type = keyrest)])
36+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = true}, originName = foo, blockDepth = 0, parseName = Object#foo, notes = null, argumentDescriptors = [ArgumentDescriptor(name = null, type = nokey)])
3737
split = HEURISTIC
3838
children:
3939
body =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public enum ArgumentType {
3838
anonreq("req", true),
3939
anonopt("opt", true),
4040
anonrest("rest", true),
41-
anonkeyrest("keyrest", true);
41+
anonkeyrest("keyrest", true),
42+
nokey("nokey", true); // **nil
4243

4344
ArgumentType(String symbolicName, boolean anonymous) {
4445
this.symbolicName = symbolicName;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.truffleruby.parser.ast.KeywordArgParseNode;
3838
import org.truffleruby.parser.ast.LocalAsgnParseNode;
3939
import org.truffleruby.parser.ast.MultipleAsgnParseNode;
40+
import org.truffleruby.parser.ast.NoKeywordsArgParseNode;
4041
import org.truffleruby.parser.ast.OptArgParseNode;
4142
import org.truffleruby.parser.ast.ParseNode;
4243
import org.truffleruby.parser.ast.RequiredKeywordArgumentValueParseNode;
@@ -136,6 +137,8 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsParseNode a
136137

137138
if (argName.equals(ParserSupport.KWREST_VAR)) {
138139
descs.add(new ArgumentDescriptor(ArgumentType.anonkeyrest, argName));
140+
} else if (argsNode.getKeyRest() instanceof NoKeywordsArgParseNode) {
141+
descs.add(new ArgumentDescriptor(ArgumentType.nokey));
139142
} else {
140143
descs.add(new ArgumentDescriptor(ArgumentType.keyrest, argsNode.getKeyRest().getName()));
141144
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.ArrayList;
1313
import java.util.List;
1414

15-
import org.truffleruby.Layouts;
1615
import org.truffleruby.RubyLanguage;
1716
import org.truffleruby.language.RubyNode;
1817
import org.truffleruby.language.arguments.CheckNoKeywordArgumentsNode;
@@ -32,8 +31,6 @@
3231

3332
public final class YARPLoadArgumentsTranslator extends AbstractNodeVisitor<RubyNode> {
3433

35-
static final String DEFAULT_NO_KEYWORD_REST_NAME = Layouts.TEMP_PREFIX + "nil_kwrest";
36-
3734
private final Arity arity;
3835
private final boolean isProc;
3936
private final boolean isMethod;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ private ArgumentDescriptor[] parametersNodeToArgumentDescriptors(Nodes.Parameter
22902290
descriptors.add(new ArgumentDescriptor(ArgumentType.keyrest, keywordRestParameterNode.name));
22912291
}
22922292
} else if (parametersNode.keyword_rest instanceof Nodes.NoKeywordsParameterNode) {
2293-
final var descriptor = new ArgumentDescriptor(ArgumentType.keyrest, YARPLoadArgumentsTranslator.DEFAULT_NO_KEYWORD_REST_NAME);
2293+
final var descriptor = new ArgumentDescriptor(ArgumentType.nokey);
22942294
descriptors.add(descriptor);
22952295
} else {
22962296
throw CompilerDirectives.shouldNotReachHere();

0 commit comments

Comments
 (0)