Why Julia fails to infere types in this example? What is the cost of this? What are requirements for type inference?

Exactly, if I execute it, @code_warntype works as expected. Isn’t it weird?