Skip to content

Commit c45dcf1

Browse files
committed
Fix nested it parameter completion
1 parent ca96d8d commit c45dcf1

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/repl_type_completor/type_analyzer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def evaluate_call_node(node, scope)
259259
call_block_proc = ->(block_args, block_self_type) do
260260
scope.conditional do |s|
261261
params_table = node.block.locals.to_h { [_1.to_s, Types::NIL] }
262+
if node.block.parameters.is_a?(Prism::ItParametersNode)
263+
params_table['_1'] = block_args.first || Types::NIL
264+
end
262265
table = { **params_table, Scope::BREAK_RESULT => nil, Scope::NEXT_RESULT => nil }
263266
block_scope = Scope.new s, table, self_type: block_self_type, trace_ivar: !block_self_type
264267
# TODO kwargs
@@ -267,8 +270,6 @@ def evaluate_call_node(node, scope)
267270
assign_numbered_parameters node.block.parameters.maximum, block_scope, block_args, {}
268271
when Prism::BlockParametersNode
269272
assign_parameters node.block.parameters.parameters, block_scope, block_args, {}
270-
when Prism::ItParametersNode
271-
scope['_1'] = block_args.first || Types::NIL
272273
end
273274
result = node.block.body ? evaluate(node.block.body, block_scope) : Types::NIL
274275
block_scope.merge_jumps

test/repl_type_completor/test_type_analyze.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ def test_it_parameter
560560
assert_call('[1].tap{it.', include: Array)
561561
assert_call('loop{it.', include: NilClass, exclude: Object)
562562
assert_call('[:a].each_with_index{it.', include: Symbol, exclude: [Integer, Array])
563+
assert_call(':outer.tap{p it; "inner".tap{p it; it.', include: String, exclude: Symbol)
564+
assert_call(':outer.tap{p it; "inner".tap{p it }; it.', include: Symbol, exclude: String)
563565
end
564566

565567
def test_if_unless

0 commit comments

Comments
 (0)