Inheritance of type of self (or new)

Okay, I played around with it a bit and discovered something interesting

The solution by @RespiteSage has the correct compile type indeed, but when accessing it, a stack overflow error is thrown (carc.in here). So that’s a no-go. (btw, why does that happen?)

So to be more exact, I am trying to do something like

class Person
  def self.instance
    @@instance ||= new
  end
end

class John < Person
  def hello
    p "Hello from John"
  end
end

class Greeter
  @@person : John = John.instance

  def self.greet
    @@person.hello
  end
end

Greeter.greet

This code above does NOT compile, because the compile type of instance is Person+ and not John. So even though @asterite is correct about the runtime type, it doesn’t really help in this scenario.

Thanks again :slight_smile: