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

Inconsistent closure type inference with conditional branch type restriction #7817

Closed
RomainFranceschini opened this issue May 23, 2019 · 3 comments

Comments

@RomainFranceschini
Copy link
Contributor

RomainFranceschini commented May 23, 2019

def foo
  yield
end

bar = rand > 0.5 ? 42 : nil
if b = bar
  c = ->() { puts "hello #{b.succ}" } # => undefined method 'succ' for Nil (compile-time type is (Int32 | Nil))
  foo(&c)
end

Since b is restricted to Int32 in this condition branch, the closure should also capture it as an Int32, not (Int32 | Nil).

Probably related to: #6037

@asterite
Copy link
Member

Duplicate of #3093

@asterite asterite marked this as a duplicate of #3093 May 23, 2019
@RomainFranceschini
Copy link
Contributor Author

Sorry I missed the original issue

@asterite
Copy link
Member

@rumenzu No problem, it serves as a count of how many people are affected by the bug :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants