Skip to content
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
5 changes: 4 additions & 1 deletion lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,10 @@ def synthesize(node, hint: nil, condition: false)
yield_self do
left_node, right_node = node.children

left_type, constr, left_context = synthesize(left_node, hint: hint, condition: true).to_ary
if hint
left_hint = union_type_unify(hint, AST::Builtin.nil_type, AST::Builtin.false_type)
end
left_type, constr, left_context = synthesize(left_node, hint: left_hint, condition: true).to_ary

interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing, config: builder_config)
left_truthy, left_falsy = interpreter.eval(env: left_context.type_env, node: left_node)
Expand Down
5 changes: 5 additions & 0 deletions sample/lib/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ def foo(...)
bar(self, ...).to_s
end
end



conference = nil #: Conference?

26 changes: 26 additions & 0 deletions test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1507,4 +1507,30 @@ def test_lambda__hint_is_untyped
YAML
)
end

def test_safe_navigation_operator__or_hint
run_type_check_test(
signatures: {
"a.rbs" => <<~RBS
class Hello
def foo: (Integer?) -> Integer
end
RBS
},
code: {
"a.rb" => <<~RUBY
class Hello
def foo(a)
a&.then {|x| x.infinite? } || -1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steep reported a confusing type error:

Cannot find compatible overloading of method `then` of type `::Integer`

It was because the hint given to &.then call is Integer, and it is forwarded to block typing where x.infinite? has Integer?.

end
end
RUBY
},
expectations: <<~YAML
---
- file: a.rb
diagnostics: []
YAML
)
end
end