chuck icon indicating copy to clipboard operation
chuck copied to clipboard

Subclasses can't call parent class functions if instantiated before class definition

Open nshaheed opened this issue 2 years ago • 0 comments

If there's a subclass B of class A, you can instantiate an object B before its definition in a file, but you can't call any parent functions from A

i.e. this works:

class Test {
    fun int test() {
        return 3;
    }
}

class SubTest extends Test {
    
}

SubTest b;
<<< b.test() >>>;

but this gives the compile error [untitled]:line(2): class 'SubTest' has no member 'test'

SubTest a;
<<< a.test() >>>;

class Test {
    fun int test() {
        return 3;
    }
}

class SubTest extends Test {   
}

This should probably instead have one of two behaviors:

  • Don't allow any instantiations of a class before it's defined in a file
  • Allow the above behavior, but the value checking should work

nshaheed avatar Apr 15 '22 17:04 nshaheed