Skip to content

Commit 5bcbf18

Browse files
authored
Merge pull request #31 from ruby/operator_write_node_deprecation_fix
Update required prism to >= 0.29.0 and fix deprecation warning
2 parents 4e27333 + 968e054 commit 5bcbf18

4 files changed

Lines changed: 10 additions & 35 deletions

File tree

.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.28.0', '0.27.0', '0.24.0', '0.21.0', '0.19.0']
56+
prism: ['latest', '0.30.0', '0.29.0']
5757
env:
5858
GEMFILE_PRISM_VERSION: ${{ matrix.prism }}
5959
steps:

lib/repl_type_completor.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,7 @@ def analyze_code(code, binding = Object::TOPLEVEL_BINDING)
111111
[:const, name, Types::SingletonType.new(Object), scope]
112112
end
113113
when Prism::ConstantReadNode, Prism::ConstantTargetNode
114-
name = target_node.name.to_s
115-
if parents.last.is_a? Prism::ConstantPathNode
116-
path_node = parents.last
117-
if path_node.parent # A::B
118-
receiver, scope = calculate_type_scope.call(path_node.parent)
119-
[:const, name, receiver, scope]
120-
else # ::A
121-
scope = calculate_scope.call
122-
[:const, name, Types::SingletonType.new(Object), scope]
123-
end
124-
else
125-
[:const, name, nil, calculate_scope.call]
126-
end
114+
[:const, target_node.name.to_s, nil, calculate_scope.call]
127115
when Prism::GlobalVariableReadNode, Prism::GlobalVariableTargetNode
128116
[:gvar, target_node.name.to_s, calculate_scope.call]
129117
when Prism::InstanceVariableReadNode, Prism::InstanceVariableTargetNode

lib/repl_type_completor/type_analyzer.rb

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,14 @@ def evaluate_call_write(node, scope, operator, write_name)
342342
Types::UnionType[left, right]
343343
else
344344
right = evaluate node.value, scope
345-
method_call left, node.operator, [right], nil, nil, scope, name_match: false
345+
method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
346346
end
347347
end
348348

349349
def evaluate_variable_operator_write(node, scope)
350350
left = scope[node.name.to_s] || Types::OBJECT
351351
right = evaluate node.value, scope
352-
scope[node.name.to_s] = method_call left, node.operator, [right], nil, nil, scope, name_match: false
352+
scope[node.name.to_s] = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
353353
end
354354
alias evaluate_global_variable_operator_write_node evaluate_variable_operator_write
355355
alias evaluate_local_variable_operator_write_node evaluate_variable_operator_write
@@ -378,7 +378,7 @@ def evaluate_variable_or_write(node, scope)
378378
def evaluate_constant_operator_write_node(node, scope)
379379
left = scope[node.name.to_s] || Types::OBJECT
380380
right = evaluate node.value, scope
381-
scope[node.name.to_s] = method_call left, node.operator, [right], nil, nil, scope, name_match: false
381+
scope[node.name.to_s] = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
382382
end
383383

384384
def evaluate_constant_and_write_node(node, scope)
@@ -395,7 +395,7 @@ def evaluate_constant_or_write_node(node, scope)
395395
def evaluate_constant_path_operator_write_node(node, scope)
396396
left, receiver, _parent_module, name = evaluate_constant_node_info node.target, scope
397397
right = evaluate node.value, scope
398-
value = method_call left, node.operator, [right], nil, nil, scope, name_match: false
398+
value = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
399399
const_path_write receiver, name, value, scope
400400
value
401401
end
@@ -419,8 +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 = const_path_name(node.target)
423-
const_path_write receiver, name, value, scope
422+
const_path_write receiver, node.target.name.to_s, value, scope
424423
value
425424
end
426425

@@ -839,16 +838,6 @@ def evaluate_call_node_arguments(call_node, scope)
839838
[args_types, kwargs_types, block_sym_node, !!block_arg]
840839
end
841840

842-
def const_path_name(node)
843-
if node.respond_to?(:name)
844-
# ConstantPathNode#name ConstantPathTargetNode#name is added in Prism 0.28.0
845-
node.name.to_s
846-
else
847-
# ConstantPathNode#child ConstantPathTargetNode#child is deprecated in Prism 0.28.0
848-
node.child.name.to_s
849-
end
850-
end
851-
852841
def const_path_write(receiver, name, value, scope)
853842
if receiver # receiver::A = value
854843
singleton_type = receiver.types.find { _1.is_a? Types::SingletonType }
@@ -875,9 +864,9 @@ def assign_required_parameter(node, value, scope)
875864
end
876865

877866
def evaluate_constant_node_info(node, scope)
867+
name = node.name.to_s
878868
case node
879869
when Prism::ConstantPathNode
880-
name = const_path_name(node)
881870
if node.parent
882871
receiver = evaluate node.parent, scope
883872
if receiver.is_a? Types::SingletonType
@@ -893,7 +882,6 @@ def evaluate_constant_node_info(node, scope)
893882
type = Types::NIL
894883
end
895884
when Prism::ConstantReadNode
896-
name = node.name.to_s
897885
type = scope[name]
898886
end
899887
@dig_targets.resolve type, scope if @dig_targets.target? node
@@ -1048,8 +1036,7 @@ def evaluate_write(node, value, scope, evaluated_receivers)
10481036
scope[node.name.to_s] = value
10491037
when Prism::ConstantPathTargetNode
10501038
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
1051-
name = const_path_name(node)
1052-
const_path_write receiver, name, value, scope
1039+
const_path_write receiver, node.name.to_s, value, scope
10531040
end
10541041
end
10551042

repl_type_completor.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
2929
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3030
spec.require_paths = ["lib"]
3131

32-
spec.add_dependency "prism", ">= 0.19.0"
32+
spec.add_dependency "prism", ">= 0.29.0"
3333
spec.add_dependency "rbs", ">= 2.7.0", "< 4.0.0"
3434
end

0 commit comments

Comments
 (0)