I encounered a format bug.
Working code:
new_hash = {} of String => String | (Int32, Hash(String, String))
Error message:
10:48 $ crystal tool format --show-backtrace './src/consul/util.cr'
expecting CONST, not `,, `, at :52:49 (Exception)
from ???
10:48 $ crystal -v
Crystal 0.30.0 [cbf651aff] (2019-08-01)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
Why does that even compile?
(resulting type of new_hash is Hash(String, Hash(String, String) | Int32 | String))
Is it an obscure undocumented syntax? Or a leftover from old times?
@bew It's the Hash equivalent to the array [] of Type syntax.
Is a sentence about it in https://crystal-lang.org/reference/syntax_and_semantics/literals/hash.html#generic-type-argument.
(Int32, Hash(String, String)) is the beginning of parsing a proc type, like (A, B -> C) but there's no -> so that shouldn't compile. This is a parser bug.
Most helpful comment
(Int32, Hash(String, String))is the beginning of parsing a proc type, like(A, B -> C)but there's no->so that shouldn't compile. This is a parser bug.