Crystal: Can't format `NamedTuple(foo: Int32 bar: Bool)`

Created on 21 Apr 2018  Β·  5Comments  Β·  Source: crystal-lang/crystal

The formatter can't format the following code: (@MakeNowJust :smiley:)

p NamedTuple(foo: Int32 bar: Bool).types

(there is no comma and it compiles! https://carc.in/#/r/3wvz)


NOTE: This syntax only works for the generic type, not in actual named tuples.
I think the syntax can be confusing, I'd suggest to remove it (by making the comma mandatory).

Most helpful comment

I think it should not be compiled and this is a simple parser bug.
-- εœŸζ›œζ—₯, 21 4月 2018, 00:29午後 +09:00 from Benoit de Chezelles [email protected] :

The formatter can't format the following code: ( @MakeNowJust πŸ˜ƒ)
p NamedTuple(foo: Int32 bar: Bool).types

(there is no comma and it compiles! https://carc.in/#/r/3wvz )

NOTE: This syntax only works for the generic type, not in actual named tuples.
I think the syntax can be quite confusing, I'd suggest to remove it (by making the comma mandatory).
β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .

All 5 comments

I think it should not be compiled and this is a simple parser bug.
-- εœŸζ›œζ—₯, 21 4月 2018, 00:29午後 +09:00 from Benoit de Chezelles [email protected] :

The formatter can't format the following code: ( @MakeNowJust πŸ˜ƒ)
p NamedTuple(foo: Int32 bar: Bool).types

(there is no comma and it compiles! https://carc.in/#/r/3wvz )

NOTE: This syntax only works for the generic type, not in actual named tuples.
I think the syntax can be quite confusing, I'd suggest to remove it (by making the comma mandatory).
β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .

I don't think that's a parser bug, just a feature that's never used and that looks weird to me with the rest of the language.

Just to add, this bug actually goes a bit deeper. Because when you compile you will not see any error, but when you are using Sublime for Crystal (or a console that runs crystal tool format on save), the formatter will echo out an Error: expecting ,, not IDENT, and ask the user to run a stack-trace. This will cause a small delay when saving files on WSL. Once the , was added, the delay went away, and the console flash is now instant.

"parser bug" means and I guess the author of NamedTuple parser does not intend to accept such a syntax. Is there a spec for this?

εœŸζ›œζ—₯, 21 4月 2018, 00:40午後 +09:00 from Benoit de Chezelles [email protected] :

I don't think that's a parser bug, just a feature that's never used and that looks weird to me with the rest of the language.
β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .

Good point, I can't find a spec for that

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbguilherme picture lbguilherme  Β·  3Comments

cjgajard picture cjgajard  Β·  3Comments

costajob picture costajob  Β·  3Comments

RX14 picture RX14  Β·  3Comments

Papierkorb picture Papierkorb  Β·  3Comments