prg-titech / Kanon

A live programming environment specialized for data structure programming.
https://prg-titech.github.io/Kanon/
MIT License
68 stars 4 forks source link

Is inheritance supported? #16

Open masuhar opened 6 years ago

masuhar commented 6 years ago

With this code

class C { }
class D extends C {
    constructor() {}
}
var v = new D()

I get an error Error?: |this| used uninitialized in D class constructor

image

It reminds me a restriction in Java, where you should write a call to the super-constructor at the beginning of a constructor. You are also not safe to access fields of this before finishing the call to the super-constructor.

masuhar commented 1 month ago

The cause of the problem:

  1. in JS, it seems that a constructor of a subclass must call super() before using this.
  2. Kanon inserts checkpoints inside of a constructor that uses this.
  3. Hence the error.

But changing the class D to this won't help:

class D extends C {
  constructor(){ super(); }
}

Though this is a correct program, Kanon inserts checkpoints before super(), which violates the use of thiis before super().

masuhar commented 1 month ago

Conclusion: we should fix the instrumentation algorithm to properly treat super calls.