Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support send in op_send lhs #186

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ def synthesize(node, hint: nil)

constr.add_typing(node, type: type)

when :send
new_rhs = rhs.updated(:send, [lhs, node.children[1], node.children[2]])
new_node = lhs.updated(:send, [lhs.children[0], :"#{lhs.children[1]}=", *lhs.children.drop(2), new_rhs])

type, constr = synthesize(new_node, hint: hint)

constr.add_typing(node, type: type)

else
Steep.logger.error("Unexpected op_asgn lhs: #{lhs.type}")

Expand Down
19 changes: 19 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,25 @@ def test_op_asgn
end
end

def test_op_asgn_send
with_checker <<-RBS do |checker|
class WithAttribute
attr_accessor foo: String
end
RBS
source = parse_ruby(<<-EOF)
a = WithAttribute.new
a.foo += "!!"
EOF

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

assert_no_error typing
end
end
end

def test_while0
with_checker do |checker|
source = parse_ruby(<<-RUBY)
Expand Down