The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
::
e.g. inside Digest::MD5
Digest::MD5
with large enums, should crystal have a cap on trying to expand cases for exhaustive case?
select
to handle the case where there is no value ready to be consumed. E.g. https://lbarasti.com/post/select_statement/#non-blocking-channel-operations
Hello, I have a type-narrowing question. I have the following code:
tweets.each do |tweet|
if tweet.referenced_tweets
parent_tweet = tweet.referenced_tweets.first
# do stuff
end
end
When I run crystal build
, I get the following error:
271 | parent_tweet = tweet.referenced_tweets.first
^----
Error: undefined method 'first' for Nil (compile-time type is (Array(ReferencedTweet) | Nil))
I'm a little confused, since according to the crystal docs as I understand them here https://crystal-lang.org/reference/1.4/syntax_and_semantics/if_var.html, I've already ruled out the possibility of .referenced_tweets
being nil
by the check if tweets.referenced_tweets
. I additionally tried with if !tweets.referenced_tweets.nil?
, and I get the same problem.
What am I missing here?