Skip to content

Commit

Permalink
Apply logic-type evaluation only if the node is :send
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jun 6, 2022
1 parent b7955de commit 35bd27c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/steep/type_inference/logic_type_interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ def eval(env:, type:, node:)
end
end
when AST::Types::Logic::Not
receiver, * = value_node.children
receiver_type = typing.type_of(node: receiver)
falsy_env, truthy_env = eval(env: env, type: receiver_type, node: receiver)
case value_node.type
when :send
receiver, * = value_node.children
receiver_type = typing.type_of(node: receiver)
falsy_env, truthy_env = eval(env: env, type: receiver_type, node: receiver)
end
end
else
_, vars = decompose_value(node)
Expand Down
15 changes: 15 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5877,6 +5877,21 @@ def test_logic_not
end
end

def test_logic_not2
with_checker(<<-RBS) do |checker|
RBS
source = parse_ruby(<<-RUBY)
a = !Object.new
a || true
RUBY

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

def test_logic_and
with_checker(<<-RBS) do |checker|
RBS
Expand Down

0 comments on commit 35bd27c

Please sign in to comment.