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 from accessing instance variable in super before it's set in subclass #6132

Open
manveru opened this issue May 26, 2018 · 3 comments
Open

Comments

@manveru
Copy link
Contributor

manveru commented May 26, 2018

This happens with 0.24.1, 0.24.2, and master, but for completeness here's the version string of master:

Crystal 0.24.2 (2018-05-26)
LLVM: 5.0.1
Default target: x86_64-unknown-linux-gnu

The OS is NixOS.

class Base
  property last_value : String

  def initialize
    @last_value = data
  end
end

class Sub < Base
  property url : String

  def initialize
    super
    @url = ""
  end

  def data
    url
  end
end

pp Sub.new.last_value

Moving @url = "" before the super fixes the crash, but that should be caught by the compiler.

Backtrace is:

Invalid memory access (signal 11) at address 0x4
[0x446886] *CallStack::print_backtrace:Int32 +118
[0x43afbb] __crystal_sigfault_handler +75
[0x7f07fe4d0dd0] ???
[0x44b070] *String#chomp:String +352
[0x44c8b3] *String#pretty_print<PrettyPrint>:Nil +275
[0x485175] *PrettyPrint::format<String, IO::FileDescriptor, Int32, String, Int32>:IO::FileDescriptor +117
[0x4850f3] *PrettyPrint::format<String, IO::FileDescriptor, Int32>:IO::FileDescriptor +67
[0x43b010] *pp<String>:String +32
[0x42dea2] __crystal_main +1730
[0x483946] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +6
[0x483812] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +50
[0x438e86] main +6
[0x7f07fd8b6020] __libc_start_main +240
[0x42d72a] _start +42
[0x0] ???
@wooster0
Copy link
Contributor

Can this be reduced to

module Hello
  def self.hello
    print @@hello

    "hello"
  end
  
  @@hello : String = hello()
end

maybe?

@asterite
Copy link
Member

No, the original example mentions an instance variable. It's just a different bug. I actually can make the second one compile but it will still crash with a stack overflow.

@manveru
Copy link
Contributor Author

manveru commented Oct 13, 2023

Well, just wanted to say this still happens on 1.9.2

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

5 participants