Crystal: formatter bug

Created on 21 Aug 2019  路  3Comments  路  Source: crystal-lang/crystal

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
bug topicparser

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  3Comments

cjgajard picture cjgajard  路  3Comments

jhass picture jhass  路  3Comments

Papierkorb picture Papierkorb  路  3Comments

oprypin picture oprypin  路  3Comments