Skip to content

Commit d0e4fe3

Browse files
committed
ConstantPathNode name to a helper method
1 parent d1f0227 commit d0e4fe3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/repl_type_completor/type_analyzer.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def evaluate_constant_path_or_write_node(node, scope)
419419
def evaluate_constant_path_write_node(node, scope)
420420
receiver = evaluate node.target.parent, scope if node.target.parent
421421
value = evaluate node.value, scope
422-
name = node.target.respond_to?(:name) ? node.target.name.to_s : node.target.child.name.to_s
422+
name = const_path_name(node.target)
423423
const_path_write receiver, name, value, scope
424424
value
425425
end
@@ -844,6 +844,16 @@ def evaluate_call_node_arguments(call_node, scope)
844844
[args_types, kwargs_types, block_sym_node, !!block_arg]
845845
end
846846

847+
def const_path_name(node)
848+
if node.respond_to?(:name)
849+
# ConstantPathNode#name ConstantPathTargetNode#name is added in Prism 0.28.0
850+
node.name.to_s
851+
else
852+
# ConstantPathNode#child ConstantPathTargetNode#child is deprecated in Prism 0.28.0
853+
node.child.name.to_s
854+
end
855+
end
856+
847857
def const_path_write(receiver, name, value, scope)
848858
if receiver # receiver::A = value
849859
singleton_type = receiver.types.find { _1.is_a? Types::SingletonType }
@@ -872,7 +882,7 @@ def assign_required_parameter(node, value, scope)
872882
def evaluate_constant_node_info(node, scope)
873883
case node
874884
when Prism::ConstantPathNode
875-
name = node.respond_to?(:name) ? node.name.to_s : node.child.name.to_s
885+
name = const_path_name(node)
876886
if node.parent
877887
receiver = evaluate node.parent, scope
878888
if receiver.is_a? Types::SingletonType
@@ -1043,7 +1053,7 @@ def evaluate_write(node, value, scope, evaluated_receivers)
10431053
scope[node.name.to_s] = value
10441054
when Prism::ConstantPathTargetNode
10451055
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
1046-
name = node.respond_to?(:name) ? node.name.to_s : node.child.name.to_s
1056+
name = const_path_name(node)
10471057
const_path_write receiver, name, value, scope
10481058
end
10491059
end

0 commit comments

Comments
 (0)