Crystal: trailing conditionals v.s conditional blocks

Created on 25 Apr 2017  路  1Comment  路  Source: crystal-lang/crystal

This wont compile

socket.close rescue nil if socket.is_a?(TCPSocket)

This will:

if socket.is_a?(TCPSocket)
  socket.close rescue nil
end

The first one returns:

undefined method 'close' for Nil (compile-time type is (TCPSocket | Nil)) (did you mean 'clone'?)

                      socket.close rescue nil if socket.is_a?(TCPSocket)

bug topicparser

Most helpful comment

For reference, this works:

(socket.close rescue nil) if socket.is_a?(TCPSocket)

It's being parsed as

socket.close rescue (nil if socket.is_a?(TCPSocket))

>All comments

For reference, this works:

(socket.close rescue nil) if socket.is_a?(TCPSocket)

It's being parsed as

socket.close rescue (nil if socket.is_a?(TCPSocket))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MakeNowJust picture MakeNowJust  路  64Comments

fridgerator picture fridgerator  路  79Comments

RX14 picture RX14  路  62Comments

xtagon picture xtagon  路  132Comments

stugol picture stugol  路  70Comments