Skip to content

Commit 1e93b22

Browse files
authored
Merge pull request #27 from ruby/catchup_with_constant_path_node_change
Catchup with ConstantPathNode change
2 parents 5879331 + d0e4fe3 commit 1e93b22

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-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: 15 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 = const_path_name(node.target)
423+
const_path_write receiver, name, value, scope
423424
value
424425
end
425426

@@ -843,6 +844,16 @@ def evaluate_call_node_arguments(call_node, scope)
843844
[args_types, kwargs_types, block_sym_node, !!block_arg]
844845
end
845846

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+
846857
def const_path_write(receiver, name, value, scope)
847858
if receiver # receiver::A = value
848859
singleton_type = receiver.types.find { _1.is_a? Types::SingletonType }
@@ -871,7 +882,7 @@ def assign_required_parameter(node, value, scope)
871882
def evaluate_constant_node_info(node, scope)
872883
case node
873884
when Prism::ConstantPathNode
874-
name = node.child.name.to_s
885+
name = const_path_name(node)
875886
if node.parent
876887
receiver = evaluate node.parent, scope
877888
if receiver.is_a? Types::SingletonType
@@ -1042,7 +1053,8 @@ def evaluate_write(node, value, scope, evaluated_receivers)
10421053
scope[node.name.to_s] = value
10431054
when Prism::ConstantPathTargetNode
10441055
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
1045-
const_path_write receiver, node.child.name.to_s, value, scope
1056+
name = const_path_name(node)
1057+
const_path_write receiver, name, value, scope
10461058
end
10471059
end
10481060

0 commit comments

Comments
 (0)