Skip to content

Commit d1f0227

Browse files
committed
Catchup with ConstantPathNode change
ConstantPathNode#child is deprecated and does not appear in child_nodes
1 parent 5879331 commit d1f0227

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
prism: ['latest', '0.27.0', '0.24.0', '0.21.0', '0.19.0']
56+
prism: ['latest', '0.28.0', '0.27.0', '0.24.0', '0.21.0', '0.19.0']
5757
env:
5858
GEMFILE_PRISM_VERSION: ${{ matrix.prism }}
5959
steps:

lib/repl_type_completor.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ 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
105+
name = target_node.name.to_s
106+
if target_node.parent # A::B
107+
receiver, scope = calculate_type_scope.call(target_node.parent)
108+
[:const, name, receiver, scope]
109+
else # ::A
110+
scope = calculate_scope.call
111+
[:const, name, Types::SingletonType.new(Object), scope]
112+
end
104113
when Prism::ConstantReadNode, Prism::ConstantTargetNode
105114
name = target_node.name.to_s
106115
if parents.last.is_a? Prism::ConstantPathNode

lib/repl_type_completor/type_analyzer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ 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-
const_path_write receiver, node.target.child.name.to_s, value, scope
422+
name = node.target.respond_to?(:name) ? node.target.name.to_s : node.target.child.name.to_s
423+
const_path_write receiver, name, value, scope
423424
value
424425
end
425426

@@ -871,7 +872,7 @@ def assign_required_parameter(node, value, scope)
871872
def evaluate_constant_node_info(node, scope)
872873
case node
873874
when Prism::ConstantPathNode
874-
name = node.child.name.to_s
875+
name = node.respond_to?(:name) ? node.name.to_s : node.child.name.to_s
875876
if node.parent
876877
receiver = evaluate node.parent, scope
877878
if receiver.is_a? Types::SingletonType
@@ -1042,7 +1043,8 @@ def evaluate_write(node, value, scope, evaluated_receivers)
10421043
scope[node.name.to_s] = value
10431044
when Prism::ConstantPathTargetNode
10441045
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
1045-
const_path_write receiver, node.child.name.to_s, value, scope
1046+
name = node.respond_to?(:name) ? node.name.to_s : node.child.name.to_s
1047+
const_path_write receiver, name, value, scope
10461048
end
10471049
end
10481050

0 commit comments

Comments
 (0)