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

Fix unexpected error when or-asgn/and-asgn #517

Merged
merged 1 commit into from
Mar 20, 2022
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
11 changes: 4 additions & 7 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2275,13 +2275,10 @@ def synthesize(node, hint: nil, condition: false)
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
])
children = asgn.children.dup
children[1] = :"#{children[1]}="
send_arg_nodes = [*children, rhs]
rhs_ = node.updated(:send, send_arg_nodes)
node_type = case node.type
when :or_asgn
:or
Expand Down
35 changes: 35 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,41 @@ def test_or_and_asgn
end
end

def test_or_and_asgn_method
with_checker(<<-RBS) do |checker|
class OrAndAsgn
def or_asgn: () -> Integer
def and_asgn: () -> Integer
def var=: (Integer) -> Integer
end
RBS
source = parse_ruby(<<-'EOF')
class OrAndAsgn
def or_asgn
self.var ||= 1
end

def and_asgn
self.var &&= 2
end

def var=(a)
a
end
end
EOF

with_standard_construction(checker, source) do |construction, typing|
construction.synthesize(source.node)
assert_equal 2, typing.errors.size
assert_all typing.errors do |error|
assert_equal :var, error.method
error.is_a?(Diagnostic::Ruby::NoMethod)
end
end
end
end

def test_next
with_checker do |checker|
source = parse_ruby(<<-'EOF')
Expand Down