assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

fix: override keyword shouldn't throw error in multilevel inherit

Open HerrCai0907 opened this issue 3 years ago • 4 comments

fix override keyword in following case

class A {
  foo(): void {}
}
class B extends A {
  bar(): void {}
}
class C extends B {
  override foo(): void {}. // should not throw error
}
  • [x] I've read the contributing guidelines
  • [x] I've added my name and email to the NOTICE file

HerrCai0907 avatar Aug 19 '22 03:08 HerrCai0907

Wondering why this didn't work before. Can you provide some context of what was missing exactly? Would assume that B inhereits foo from A, and then C upon extending sees foo, overriding it.

dcodeIO avatar Aug 20 '22 15:08 dcodeIO

Wondering why this didn't work before. Can you provide some context of what was missing exactly? Would assume that B inhereits foo from A, and then C upon extending sees foo, overriding it.

But B's baseInstanceMembers don't have A's member, so need to search all the node in inherit chain and throw the error at the end.

HerrCai0907 avatar Aug 20 '22 23:08 HerrCai0907

Oh, I see. Makes me think this is either an oversight, or perhaps we should look up from instanceMembers if these have all of them? I wonder what I was thinking when I wrote that code :)

dcodeIO avatar Aug 20 '22 23:08 dcodeIO

Looking more closely, I think markVirtuals isn't the right place to perform the check / emit the diagnostic. That's a rather specific method, and it was likely an oversight that the prior check was added there. Looks like the check should rather be performed when resolving a class.

dcodeIO avatar Aug 26 '22 14:08 dcodeIO