[ruby/irb] Require prism >= 0.18.0 (MatchWriteNode#targets and
CaseMatchNode) (https://github.com/ruby/irb/pull/778) https://github.com/ruby/irb/commit/943c14b12e
This commit is contained in:
parent
7a93bee4f8
commit
8d6175bf64
@ -164,7 +164,7 @@ module IRB
|
|||||||
RegexpCompletor.new
|
RegexpCompletor.new
|
||||||
end
|
end
|
||||||
|
|
||||||
TYPE_COMPLETION_REQUIRED_PRISM_VERSION = '0.17.1'
|
TYPE_COMPLETION_REQUIRED_PRISM_VERSION = '0.18.0'
|
||||||
|
|
||||||
private def build_type_completor
|
private def build_type_completor
|
||||||
unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') && RUBY_ENGINE != 'truffleruby'
|
unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') && RUBY_ENGINE != 'truffleruby'
|
||||||
|
@ -703,19 +703,31 @@ module IRB
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate_case_node(node, scope)
|
def evaluate_case_node(node, scope)
|
||||||
target = evaluate(node.predicate, scope) if node.predicate
|
evaluate(node.predicate, scope) if node.predicate
|
||||||
# TODO
|
# TODO
|
||||||
branches = node.conditions.map do |condition|
|
branches = node.conditions.map do |condition|
|
||||||
->(s) { evaluate_case_match target, condition, s }
|
->(s) { evaluate_case_when_condition condition, s }
|
||||||
end
|
end
|
||||||
if node.consequent
|
if node.consequent
|
||||||
branches << ->(s) { evaluate node.consequent, s }
|
branches << ->(s) { evaluate node.consequent, s }
|
||||||
elsif node.conditions.any? { _1.is_a? Prism::WhenNode }
|
else
|
||||||
branches << ->(_s) { Types::NIL }
|
branches << ->(_s) { Types::NIL }
|
||||||
end
|
end
|
||||||
Types::UnionType[*scope.run_branches(*branches)]
|
Types::UnionType[*scope.run_branches(*branches)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def evaluate_case_match_node(node, scope)
|
||||||
|
target = evaluate(node.predicate, scope)
|
||||||
|
# TODO
|
||||||
|
branches = node.conditions.map do |condition|
|
||||||
|
->(s) { evaluate_case_in_condition target, condition, s }
|
||||||
|
end
|
||||||
|
if node.consequent
|
||||||
|
branches << ->(s) { evaluate node.consequent, s }
|
||||||
|
end
|
||||||
|
Types::UnionType[*scope.run_branches(*branches)]
|
||||||
|
end
|
||||||
|
|
||||||
def evaluate_match_required_node(node, scope)
|
def evaluate_match_required_node(node, scope)
|
||||||
value_type = evaluate node.value, scope
|
value_type = evaluate node.value, scope
|
||||||
evaluate_match_pattern value_type, node.pattern, scope
|
evaluate_match_pattern value_type, node.pattern, scope
|
||||||
@ -765,7 +777,8 @@ module IRB
|
|||||||
def evaluate_match_write_node(node, scope)
|
def evaluate_match_write_node(node, scope)
|
||||||
# /(?<a>)(?<b>)/ =~ string
|
# /(?<a>)(?<b>)/ =~ string
|
||||||
evaluate node.call, scope
|
evaluate node.call, scope
|
||||||
node.locals.each { scope[_1.to_s] = Types::UnionType[Types::STRING, Types::NIL] }
|
locals = node.targets.map(&:name)
|
||||||
|
locals.each { scope[_1.to_s] = Types::UnionType[Types::STRING, Types::NIL] }
|
||||||
Types::BOOLEAN
|
Types::BOOLEAN
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -948,12 +961,12 @@ module IRB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate_case_match(target, node, scope)
|
def evaluate_case_when_condition(node, scope)
|
||||||
case node
|
|
||||||
when Prism::WhenNode
|
|
||||||
node.conditions.each { evaluate _1, scope }
|
node.conditions.each { evaluate _1, scope }
|
||||||
node.statements ? evaluate(node.statements, scope) : Types::NIL
|
node.statements ? evaluate(node.statements, scope) : Types::NIL
|
||||||
when Prism::InNode
|
end
|
||||||
|
|
||||||
|
def evaluate_case_in_condition(target, node, scope)
|
||||||
pattern = node.pattern
|
pattern = node.pattern
|
||||||
if pattern.is_a?(Prism::IfNode) || pattern.is_a?(Prism::UnlessNode)
|
if pattern.is_a?(Prism::IfNode) || pattern.is_a?(Prism::UnlessNode)
|
||||||
cond_node = pattern.predicate
|
cond_node = pattern.predicate
|
||||||
@ -963,7 +976,6 @@ module IRB
|
|||||||
evaluate cond_node, scope if cond_node # TODO: conditional branch
|
evaluate cond_node, scope if cond_node # TODO: conditional branch
|
||||||
node.statements ? evaluate(node.statements, scope) : Types::NIL
|
node.statements ? evaluate(node.statements, scope) : Types::NIL
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def evaluate_match_pattern(value, pattern, scope)
|
def evaluate_match_pattern(value, pattern, scope)
|
||||||
# TODO: scope.terminate_with Scope::PATTERNMATCH_BREAK, Types::NIL
|
# TODO: scope.terminate_with Scope::PATTERNMATCH_BREAK, Types::NIL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user