shiika icon indicating copy to clipboard operation
shiika copied to clipboard

Calling class method from class initializer

Open yhara opened this issue 2 years ago • 0 comments

Given

class A
  def self.initialize
    A.foo
  end
  def self.foo
    ...
  end
end

This is safe if foo does not access an class instance variable of A.

Got

Compiler generates a binary but it results in SEGV.

Reason

  1. @init_A is called
  2. It tries to call @Meta_A_foo
  3. To do that, it refers the constant A to pass it as the first argument
  4. However, the constant A is null

To fix this

Refactor gen_const_inits and gen_class_literal into gen_class_constants or something.

yhara avatar Jan 22 '23 15:01 yhara