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

local variable re-assignment in rescue block doesn't merge types only after that point #4002

Closed
rdp opened this issue Feb 5, 2017 · 1 comment

Comments

@rdp
Copy link
Contributor

rdp commented Feb 5, 2017

The following works (extracted from server.cr):

  def handle_client(io)
    io.sync = false
      if tls = @tls
        io = OpenSSL::SSL::Socket::Server.new(io, tls, sync_close: true)
      end
    @processor.process(io, io)
  end

However this doesn't:

  def handle_client(io)
    io.sync = false
      if tls = @tls
         begin
            io = OpenSSL::SSL::Socket::Server.new(io, tls, sync_close: true)
         rescue ex
         end
      end
    @processor.process(io, io)
  end

crystal/src/http/server.cr:163: undefined method 'sync=' for Nil (compile-time type is (TCPSocket | Nil))
    io.sync = false

So I guess the parser is assigning the type "global to the method" in the latter case, which surprised me at the time, and may not be expected.

Thanks!

@asterite
Copy link
Member

asterite commented Feb 8, 2017

a = 1
b = a
begin
  a = 'a'
rescue
end
p typeof(b) # => Int32 | Char

but it should be Int32

@asterite asterite added this to the Next milestone Feb 8, 2017
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