The Crystal Programming Language Forum

A || b doesn't work as expected in a block

Is this a bug or something I did wrong?

def foo(&block : -> String)

s = nil

foo do
  s || "foo"


7 | foo do
Error: expected block to return String, not (String | Nil)

It’s this:

As a workaround you can assign s to a local variable inside the block, then do what you do now.