solargraph icon indicating copy to clipboard operation
solargraph copied to clipboard

File.open(filename, &block) return type inferred incorrectly

Open amake opened this issue 4 years ago • 1 comments

This code:

# @return [Integer]
def foo
  File.open('/dev/null') { |_| 1 }
end

puts foo # => 1

Typechecks incorrectly:

% solargraph typecheck --level typed test.rb 
/path/to/test.rb:2 - Declared return type Integer does not match inferred type IO for #foo
1 problem found.

It seems to be unaware that when a block is supplied, the return value is that of the block.

amake avatar Nov 12 '21 12:11 amake

Confirmed. I'm not sure how to handle this case yet, but I'll look into it.

castwide avatar Nov 17 '21 18:11 castwide