Skip to content

Commit

Permalink
Merge pull request #194 from soutaro/or_asgn_and_asgn
Browse files Browse the repository at this point in the history
Support or_asgn/and_asgn with send
  • Loading branch information
soutaro authored Aug 29, 2020
2 parents 0884d8b + 18f2148 commit 9eefa65
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1800,13 +1800,34 @@ def synthesize(node, hint: nil)
when :or_asgn, :and_asgn
yield_self do
asgn, rhs = node.children
type, constr = synthesize(rhs, hint: hint)

case asgn.type
when :lvasgn
type, constr = synthesize(rhs, hint: hint)
constr.lvasgn(asgn, type)
when :ivasgn
type, constr = synthesize(rhs, hint: hint)
constr.ivasgn(asgn, type)
when :send
rhs_ = node.updated(:send,
[
asgn.children[0],
:"#{asgn.children[1]}=",
asgn.children[2],
rhs
])
node_type = case node.type
when :or_asgn
:or
when :and_asgn
:and
end
node_ = node.updated(node_type, [asgn, rhs_])

synthesize(node_, hint: hint)
else
Steep.logger.error { "#{node.type} with #{asgn.type} lhs is not supported"}
fallback_to_any(node)
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5173,4 +5173,21 @@ def set
end
end
end

def test_orasgn_call
with_checker do |checker|
source = parse_ruby(<<-RUBY)
a = [1,2,3]
a[0] ||= 3
a[1] &&= 4
RUBY

with_standard_construction(checker, source) do |construction, typing|
construction.synthesize(source.node)

assert_no_error typing
end
end
end
end

0 comments on commit 9eefa65

Please sign in to comment.