Skip to content

Commit 43fa3e6

Browse files
committed
Fix Proc#arity and ignore implicit rest parameter
1 parent 2862665 commit 43fa3e6

File tree

192 files changed

+570
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+570
-553
lines changed

spec/ruby/core/proc/arity_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@
268268
@a.arity.should == 3
269269
@b.arity.should == 3
270270
end
271+
272+
# implicit rest
273+
evaluate <<-ruby do
274+
@a = lambda { |a, | }
275+
ruby
276+
277+
@a.arity.should == 1
278+
end
271279
end
272280

273281
context "returns negative values" do
@@ -530,6 +538,14 @@
530538
@a.arity.should == 1
531539
@b.arity.should == 5
532540
end
541+
542+
# implicit rest
543+
evaluate <<-ruby do
544+
@a = proc { |a, | }
545+
ruby
546+
547+
@a.arity.should == 1
548+
end
533549
end
534550

535551
context "returns negative values" do

spec/ruby/core/proc/parameters_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
-> x {}.parameters.should == [[:req, :x]]
9696
end
9797

98+
it "ignores implicit rest arguments" do
99+
proc { |x, | }.parameters.should == [[:opt, :x]]
100+
lambda { |x, | }.parameters.should == [[:req, :x]]
101+
end
102+
98103
ruby_version_is '3.2' do
99104
it "adds rest arg with name * for \"star\" argument" do
100105
-> * {}.parameters.should == [[:rest, :*]]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ast: |
1616
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1717
flags = 0
1818
frameOnStackMarkerSlot = 2
19-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = bar, type = block)])
19+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = bar, type = block)])
2020
type = PROC
2121
call targets:
2222
RubyProcRootNode
@@ -30,7 +30,7 @@ ast: |
3030
redoProfile = false
3131
retryProfile = false
3232
returnID = org.truffleruby.language.control.ReturnID@...
33-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = bar, type = block)])
33+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = bar, type = block)])
3434
split = HEURISTIC
3535
children:
3636
body =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ast: |
1818
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1919
flags = 0
2020
frameOnStackMarkerSlot = 2
21-
sharedMethodInfo = SharedMethodInfo(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 = other, type = keyrest)])
21+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = 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 = other, type = keyrest)])
2222
type = PROC
2323
call targets:
2424
RubyProcRootNode
@@ -32,7 +32,7 @@ ast: |
3232
redoProfile = false
3333
retryProfile = false
3434
returnID = org.truffleruby.language.control.ReturnID@...
35-
sharedMethodInfo = SharedMethodInfo(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 = other, type = keyrest)])
35+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = 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 = other, type = keyrest)])
3636
split = HEURISTIC
3737
children:
3838
body =

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 = ...$$Lambda$.../0x...@...)
2020
flags = 0
2121
frameOnStackMarkerSlot = 2
22-
sharedMethodInfo = SharedMethodInfo(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)])
22+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = 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(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)])
36+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = 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
split = HEURISTIC
3838
children:
3939
body =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ast: |
1414
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1515
flags = 0
1616
frameOnStackMarkerSlot = 2
17-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 1, optional = 0, hasRest = true, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = req)])
17+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 1, optional = 0, hasRest = true, isImplicitRest = true, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = req)])
1818
type = PROC
1919
call targets:
2020
RubyProcRootNode
@@ -28,7 +28,7 @@ ast: |
2828
redoProfile = false
2929
retryProfile = false
3030
returnID = org.truffleruby.language.control.ReturnID@...
31-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 1, optional = 0, hasRest = true, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = req)])
31+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 1, optional = 0, hasRest = true, isImplicitRest = true, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = a, type = req)])
3232
split = HEURISTIC
3333
children:
3434
body =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ast: |
1717
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1818
flags = 0
1919
frameOnStackMarkerSlot = 2
20-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}, 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)])
20+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}, 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)])
2121
type = PROC
2222
call targets:
2323
RubyProcRootNode
@@ -31,7 +31,7 @@ ast: |
3131
redoProfile = false
3232
retryProfile = false
3333
returnID = org.truffleruby.language.control.ReturnID@...
34-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}, 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)])
34+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}, 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)])
3535
split = HEURISTIC
3636
children:
3737
body =
@@ -87,7 +87,7 @@ ast: |
8787
checkKeywordArityNode =
8888
CheckKeywordArityNode
8989
attributes:
90-
arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}
90+
arity = Arity{preRequired = 0, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [a, b], requiredKeywordArgumentsCount = 2, hasKeywordsRest = false}
9191
children:
9292
readUserKeywordsHashNode =
9393
ReadUserKeywordsHashNode

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ast: |
1818
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1919
flags = 0
2020
frameOnStackMarkerSlot = 2
21-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 4, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = _1, type = req), ArgumentDescriptor(name = _2, type = req), ArgumentDescriptor(name = _3, type = req), ArgumentDescriptor(name = _4, type = req)])
21+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 4, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = _1, type = req), ArgumentDescriptor(name = _2, type = req), ArgumentDescriptor(name = _3, type = req), ArgumentDescriptor(name = _4, type = req)])
2222
type = PROC
2323
call targets:
2424
RubyProcRootNode
@@ -32,7 +32,7 @@ ast: |
3232
redoProfile = false
3333
retryProfile = false
3434
returnID = org.truffleruby.language.control.ReturnID@...
35-
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 4, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = _1, type = req), ArgumentDescriptor(name = _2, type = req), ArgumentDescriptor(name = _3, type = req), ArgumentDescriptor(name = _4, type = req)])
35+
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 4, optional = 0, hasRest = false, isImplicitRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = _1, type = req), ArgumentDescriptor(name = _2, type = req), ArgumentDescriptor(name = _3, type = req), ArgumentDescriptor(name = _4, type = req)])
3636
split = HEURISTIC
3737
children:
3838
body =

0 commit comments

Comments
 (0)