Skip to content

Commit 95d1242

Browse files
authored
Merge pull request #28 from ruby/rescue_const_path_fix
Fix rescue_node reference evaluation
2 parents 1e93b22 + bd2ca54 commit 95d1242

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

lib/repl_type_completor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def analyze_code(code, binding = Object::TOPLEVEL_BINDING)
101101
[op == '::' ? :call_or_const : :call, name, receiver_type, self_call]
102102
when Prism::LocalVariableReadNode, Prism::LocalVariableTargetNode
103103
[:lvar_or_method, target_node.name.to_s, calculate_scope.call]
104-
when Prism::ConstantPathNode
104+
when Prism::ConstantPathNode, Prism::ConstantPathTargetNode
105105
name = target_node.name.to_s
106106
if target_node.parent # A::B
107107
receiver, scope = calculate_type_scope.call(target_node.parent)

lib/repl_type_completor/type_analyzer.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,7 @@ def evaluate_rescue_node(node, scope)
579579
end
580580
error_types << Types::InstanceType.new(StandardError) if error_types.empty?
581581
error_type = Types::UnionType[*error_types]
582-
case node.reference
583-
when Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode
584-
s[node.reference.name.to_s] = error_type
585-
when Prism::CallTargetNode, Prism::IndexTargetNode
586-
evaluate_multi_write_receiver node.reference, s, nil
587-
end
582+
evaluate_write node.reference, error_type, s, nil
588583
end
589584
node.statements ? evaluate(node.statements, s) : Types::NIL
590585
end

test/repl_type_completor/test_type_analyze.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def test_rescue_assign
7474
assert_equal [:ivar, '@a'], analyze('begin; rescue => @a')[0, 2]
7575
assert_equal [:cvar, '@@a'], analyze('begin; rescue => @@a')[0, 2]
7676
assert_equal [:const, 'A'], analyze('begin; rescue => A')[0, 2]
77+
assert_equal [:const, 'B'], analyze('begin; rescue => A::B')[0, 2]
7778
assert_equal [:call, 'b'], analyze('begin; rescue => a.b')[0, 2]
79+
assert_call 'begin; rescue => (a=1)::B; a.', include: Integer
80+
assert_call 'begin; rescue => A; A.', include: StandardError
81+
assert_call 'begin; rescue => Array::A; Array::A.', include: StandardError
7882
end
7983

8084
def test_ref

0 commit comments

Comments
 (0)