crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.48k stars 1.62k forks source link

Crash when referencing class variable in instance variable initializer #6440

Open Michionlion opened 6 years ago

Michionlion commented 6 years ago

When referencing a class variable in the assignment of an instance variable, the crystal compiler errors with BUG:@@next_id = @@next_id + 1at /testing/test.cr:3:15 has no type (Exception). The code that produces this is below.

class IdHaver
  @@next_id : Int32 = 0
  @id : Int32 = @@next_id += 1
end

ider = IdHaver.new

I'm on openSUSE Leap 42.3, and the output of crystal -v is included below.

Crystal 0.25.1 [b782738ff] (2018-06-27)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
RX14 commented 6 years ago
class Foo
  @@a = 0
  @@b = (@@a = 1)
end

ider = Foo.new

reduced

any assign in the initializer for an ivar or cvar to an ivar or cvar seems to be the issue