Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when printing class variable before initialization #7913

Closed
wooster0 opened this issue Jun 21, 2019 · 2 comments
Closed

Crash when printing class variable before initialization #7913

wooster0 opened this issue Jun 21, 2019 · 2 comments

Comments

@wooster0
Copy link
Contributor

module Hello
  def self.hello
    print @@hello

    "hello"
  end
  
  @@hello : String = hello()
end
Invalid memory access (signal 11) at address 0x4
[0x561f8d549d06] *CallStack::print_backtrace:Int32 +118
[0x561f8d53d0a0] __crystal_sigfault_handler +192
[0x7fdd8ee3d4d0] ???
[0x561f8d54c485] *String#to_slice:Slice(UInt8) +21
[0x561f8d54e168] *String#to_s<IO::FileDescriptor>:Nil +24
[0x561f8d561c41] *IO::FileDescriptor +17
[0x561f8d561c26] *IO::FileDescriptor +6
[0x561f8d53d14d] *print<String>:Nil +45
[0x561f8d58a36e] *Hello::hello:String +14
[0x561f8d53d0d6] ~Hello::hello:init +6
[0x561f8d52fb61] __crystal_main +1489
[0x561f8d58a806] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +6
[0x561f8d58a769] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +41
[0x561f8d53a586] main +6
[0x7fdd8ec06ce3] __libc_start_main +243
[0x561f8d52f4be] _start +46
[0x0] ???
@jhass jhass changed the title Crash when printing instance variable before initialization Crash when printing class variable before initialization Jun 24, 2019
@vlazar
Copy link
Contributor

vlazar commented Oct 14, 2019

Now it shows this.

$ crystal test.cr
Unhandled exception: Recursion while initializing class variables and/or constants (Exception)
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/once.cr:21:9 in 'once'
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/once.cr:48:3 in '__crystal_once'
  from ~Hello::hello:read
  from test.cr:2:3 in 'hello'
  from ~Hello::hello:init
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/once.cr:255:3 in 'once'
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/once.cr:48:3 in '__crystal_once'
  from test.cr:8:22 in '__crystal_main'
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:97:5 in 'main_user_code'
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:86:7 in 'main'
  from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:106:3 in 'main'
Crystal 0.31.1 on MacOS
$ crystal --version
Crystal 0.31.1 (2019-10-02)

LLVM: 8.0.1
Default target: x86_64-apple-macosx

It seems related to #6005

@asterite
Copy link
Member

Indeed!

Fixed by #8172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants