Crystal: Error with comma variable asignment

Created on 13 Feb 2019  路  6Comments  路  Source: crystal-lang/crystal

I am using Crystal 0.27.2.
When I attempted to run the code a, b, C = 1, 2, 3, I got the following error:

Nil assertion failed (NilAssertionError)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

I am running ubuntu 18.04

bug topicsemantic

Most helpful comment

Probably... but Ruby "constants" aren't exactly constant 馃槅

All 6 comments

Yes, constants can't be assigned inside multiple assignment. We need to give a proper error message for this.

Why not?

Because multiple assignment involves creating temporary variables so that, for example, a, b = b, a can work.

Maybe we can make it work. I don't really see the benefit of supporting this, for me (personally) it's a bit unreadable that local variables and constants are assigned in a single line.

Constants are not variables and I think there is no reason to assume they would work with multiple assignments.

I think the reason for this to be wanted is that it works in Ruby. But that's not a good enough reason for me to consider including it in Crystal.

Probably... but Ruby "constants" aren't exactly constant 馃槅

Was this page helpful?
0 / 5 - 0 ratings