Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Make if const_val checks explicit
Browse files Browse the repository at this point in the history
Crystal doesn't have implicit conversion to bool based on the numerical
value of the integer. This means that even 0 evaluates to true. This
changes the check to be explicit.
  • Loading branch information
Burgos committed Jan 31, 2019
1 parent 87690cf commit 4e24062
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parser.cr
Expand Up @@ -957,7 +957,7 @@ module Isekai

begin
cond_val = evaluate(cond_state.@expr)
if cond_val
if cond_val != 0
return transform_statement(if_parts[1], symtab)
elsif if_parts.size == 3
return transform_statement(if_parts[2], symtab)
Expand Down Expand Up @@ -1016,6 +1016,7 @@ module Isekai

begin
begin
# TODO: check this
cond_val = evaluate(cond_state.@expr)
rescue ex : NonconstantExpression
Log.log.debug("Falling back to dynamic unrolling")
Expand Down Expand Up @@ -1057,7 +1058,7 @@ module Isekai
cond_val = evaluate(cond_state.@expr)

# Break?
if cond_val.is_a? Nil
if cond_val == 0
break
end

Expand Down

0 comments on commit 4e24062

Please sign in to comment.