Closed bcoe closed 5 years ago
I think that you have a good test, but I don't think we need to go overboard with restricting the productions here. It's nonsense, and very rare, probably intentional, nonsense. 😃
I tend to agree, @littledan made a similar point for another edge-case, along the lines of:
It's not our place to protect users from every weird edge-case they can create with the language.
And my example is wrong, you'd have to do something even weirder to get an exception:
class Cat extends biology?.Animal?.a {
// I believe biology?.Animal would be fine.
}
Note that you can already write nonsense like class foo extends new bar { }
or class foo extends (a + b) { }
. I don’t think that optional chaining merit more attention than any other random expression.
Today it can be determined statically, by the presence of the keyword extends
, whether a class is derived (which in practice means: whether you must use super()
in the constructor in order to construct this
). If we support “optional extends” that won’t be true any longer. I do not prospect anything in that direction.
I was putting some work into enumerating grammar productions today, and one jumped out at me:
It feels a bit weird for someone to be able to conditionally inherit:
Should this be an early error, or are folks getting the behavior they deserve for using optional chaining in a silly way?
What makes things worse is imagine this: