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

Add missing branches to make exhaustiveness check happy #8962

Merged
merged 1 commit into from
Mar 28, 2020

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Mar 28, 2020

Followup to #8678

@Sija
Copy link
Contributor Author

Sija commented Mar 28, 2020

Now when I'm looking at it there's still a when nil branch missing but compiler doesn't seem to complain...

Using compiled compiler at /Users/sija/Code/crystal/.build/crystal
In /Users/sija/Code/crystal/src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4835757792'

Called macro defined in /Users/sija/Code/crystal/src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - false

@asterite
Copy link
Member

Is nil passed in your calling code? Otherwise the compiler won't complain. The compiler checks actual values. If you specify a default value but it's not used, the compiler doesn't use it.

@asterite
Copy link
Member

I guess we need to handle nil too, even if the compiler (correctly) doesn't complain about it.

@asterite
Copy link
Member

I wonder why we didn't see this warning before... I think a change to this file was merged after we merge the exhaustiveness check. When I compile the specs for http client I get this:

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4640824944'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - Nil

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4678149552'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - Nil

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4678181648'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - false

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4678825280'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - false

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4713403040'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - false

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4714974048'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - Nil

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4734511408'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - Nil

In src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_4711526624'

Called macro defined in src/http/client.cr:132:5

 132 | {% if flag?(:without_openssl) %}

Which expanded to:

   1 |
 > 2 |       @tls = case tls
   3 |              when true
   4 |                OpenSSL::SSL::Context::Client.new
   5 |              when OpenSSL::SSL::Context::Client
   6 |                tls
   7 |              end
   8 |
Warning: case is not exhaustive.

Missing cases:
 - Nil

A total of 8 warnings were found.

It's a bit of a mess but it's fine: in the release after 0.34.0 you'll get an error for these, and you'll only see one of them (like all other errors). Then you'll have to add nil, then false and you'll be done.

@Sija
Copy link
Contributor Author

Sija commented Mar 28, 2020

@asterite I've added an else branch which handles both of those cases.

@asterite
Copy link
Member

I think we should add the explicit cases false and nil. Then if we decide to add new cases the compiler will tell us. That's the benefit of the change. So we should try to avoid adding else if possible

@Sija Sija changed the title Add missing else branch to make exhaustiveness check happy Add missing branches to make exhaustiveness check happy Mar 28, 2020
@Sija
Copy link
Contributor Author

Sija commented Mar 28, 2020

@asterite ok, done

@RX14 RX14 merged commit f968856 into crystal-lang:master Mar 28, 2020
@RX14 RX14 added this to the 0.34.0 milestone Mar 28, 2020
@RX14 RX14 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking labels Mar 28, 2020
@j8r
Copy link
Contributor

j8r commented Mar 28, 2020

@asterite I rebased master yesterday, but I didn't notice the warnings since the CI was green.

@asterite
Copy link
Member

@j8r It's fine :-)

I was worried for a minute that the check was working correctly, but it was just that this was merged after I merged my PR.

carlhoerberg pushed a commit to carlhoerberg/crystal that referenced this pull request Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants