Skip to content

Commit a1fdc0c

Browse files
committed
Fix numbered parameters in BodyTranslator
1 parent da2f423 commit a1fdc0c

File tree

7 files changed

+64
-50
lines changed

7 files changed

+64
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88
* Fix `rb_enc_left_char_head()` so it is not always `ArgumentError` (#3267, @eregon).
99
* Fix `IO.copy_stream` with a `Tempfile` destination (#3280, @eregon).
1010
* Fix `Regexp.union` negotiating the wrong result encoding (#3287, @nirvdrum, @simonlevasseur).
11+
* Fix `Proc#parameters` and return all the numbered parameters lower than the used explicitly ones (@andrykonchin).
1112

1213
Compatibility:
1314

spec/ruby/language/numbered_parameters_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@
8282
lambda { _9 }.arity.should == 9
8383
end
8484

85+
it "affects block parameters" do
86+
-> { _1 }.parameters.should == [[:req, :_1]]
87+
-> { _2 }.parameters.should == [[:req, :_1], [:req, :_2]]
88+
89+
proc { _1 }.parameters.should == [[:opt, :_1]]
90+
proc { _2 }.parameters.should == [[:opt, :_1], [:opt, :_2]]
91+
end
92+
93+
it "affects binding local variables" do
94+
-> { _1; binding.local_variables }.call("a").should == [:_1]
95+
-> { _2; binding.local_variables }.call("a", "b").should == [:_1, :_2]
96+
end
97+
8598
it "does not work in methods" do
8699
obj = Object.new
87100
def obj.foo; _1 end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fails(GR-30031):Numbered parameters warns when numbered parameter is overwritten with local variable
1+
fails(GR-30031):Numbered parameters warns when numbered parameter is overwritten with local variable

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ 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 = _4, type = req), ArgumentDescriptor(name = _4, type = req), ArgumentDescriptor(name = _4, type = req), ArgumentDescriptor(name = _4, type = req)])
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)])
2222
type = PROC
2323
call targets:
2424
RubyProcRootNode
2525
attributes:
2626
callTarget = block in <top (required)>
27-
frameDescriptor = FrameDescriptor@...{#0:(self), #1:_4, #2:%destructure_1}
27+
frameDescriptor = FrameDescriptor@...{#0:(self), #1:_1, #2:_2, #3:_3, #4:_4, #5:%destructure_1}
2828
instrumentationBits = 0
2929
lock = java.util.concurrent.locks.ReentrantLock@...[Unlocked]
3030
nextProfile = false
3131
polyglotRef = org.truffleruby.RubyLanguage@...
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 = _4, type = req), ArgumentDescriptor(name = _4, type = req), ArgumentDescriptor(name = _4, type = req), ArgumentDescriptor(name = _4, type = req)])
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)])
3636
split = HEURISTIC
3737
children:
3838
body =
@@ -64,7 +64,7 @@ ast: |
6464
WriteLocalVariableNode
6565
attributes:
6666
flags = 0
67-
frameSlot = 2
67+
frameSlot = 5
6868
children:
6969
valueNode =
7070
SplatCastNodeGen
@@ -99,7 +99,7 @@ ast: |
9999
ReadLocalVariableNode
100100
attributes:
101101
flags = 0
102-
frameSlot = 2
102+
frameSlot = 5
103103
type = FRAME_LOCAL
104104
]
105105
elseBody =
@@ -142,7 +142,7 @@ ast: |
142142
WriteLocalVariableNode
143143
attributes:
144144
flags = 0
145-
frameSlot = 1
145+
frameSlot = 2
146146
children:
147147
valueNode =
148148
ProfileArgumentNodeGen
@@ -159,7 +159,7 @@ ast: |
159159
WriteLocalVariableNode
160160
attributes:
161161
flags = 0
162-
frameSlot = 1
162+
frameSlot = 3
163163
children:
164164
valueNode =
165165
ProfileArgumentNodeGen
@@ -176,7 +176,7 @@ ast: |
176176
WriteLocalVariableNode
177177
attributes:
178178
flags = 0
179-
frameSlot = 1
179+
frameSlot = 4
180180
children:
181181
valueNode =
182182
ProfileArgumentNodeGen
@@ -226,12 +226,12 @@ ast: |
226226
ReadLocalVariableNode
227227
attributes:
228228
flags = 0
229-
frameSlot = 2
229+
frameSlot = 5
230230
type = FRAME_LOCAL
231231
WriteLocalVariableNode
232232
attributes:
233233
flags = 0
234-
frameSlot = 1
234+
frameSlot = 2
235235
children:
236236
valueNode =
237237
ArrayIndexNodesFactory$ReadConstantIndexNodeGen
@@ -243,12 +243,12 @@ ast: |
243243
ReadLocalVariableNode
244244
attributes:
245245
flags = 0
246-
frameSlot = 2
246+
frameSlot = 5
247247
type = FRAME_LOCAL
248248
WriteLocalVariableNode
249249
attributes:
250250
flags = 0
251-
frameSlot = 1
251+
frameSlot = 3
252252
children:
253253
valueNode =
254254
ArrayIndexNodesFactory$ReadConstantIndexNodeGen
@@ -260,12 +260,12 @@ ast: |
260260
ReadLocalVariableNode
261261
attributes:
262262
flags = 0
263-
frameSlot = 2
263+
frameSlot = 5
264264
type = FRAME_LOCAL
265265
WriteLocalVariableNode
266266
attributes:
267267
flags = 0
268-
frameSlot = 1
268+
frameSlot = 4
269269
children:
270270
valueNode =
271271
ArrayIndexNodesFactory$ReadConstantIndexNodeGen
@@ -277,12 +277,12 @@ ast: |
277277
ReadLocalVariableNode
278278
attributes:
279279
flags = 0
280-
frameSlot = 2
280+
frameSlot = 5
281281
type = FRAME_LOCAL
282282
]
283283
ReadLocalVariableNode
284284
attributes:
285285
flags = 1
286-
frameSlot = 1
286+
frameSlot = 4
287287
type = FRAME_LOCAL
288288
]

0 commit comments

Comments
 (0)