dotty-feature-requests
dotty-feature-requests copied to clipboard
implements keyword
A keyword that's similar to override
, but causes a compiler error if the parent method is implemented. This is good to distinguish overriding from implementing abstract methods.
Quite often, override
is used to make sure the method actually implements an abstract parent method. But if the parent method is actually implemented at a later stage, there's no way to know if something overrides it when the idea was to just implement it.
trait A {
def foo(): Unit
def bar(): Unit = ???
}
object X extends A {
// Compiles
implement def foo(): Unit = ???
override def bar(): Unit = ???
// Doesn't compile
implement def bar(): Unit = ???
implement def newMethod(): Unit = ???
}
YES, please. It's really good to know if a method is "new" or implements something abstract. Too many times have I removed foo
from A and forgotten to remove the implementation in X
because it didn't have override
.
Having a distinct keyword for implement
helps:
- accidentally overriding a concrete implementation
- accidentally forgetting to implement an abstract implementation
- accidentally not implementing anything because there's nothing to implement
@bishabosha is there something I can do to help make this happen?
Note that we're releasing Scala 3.0 in a few months, so now is not really the best time for throwing in more new features :). In any case, something like that would have to go through the SIP process: https://docs.scala-lang.org/sips/ (but the SIP committee is busy with existing Dotty features for now)
Understood, maybe in a future release then :)
I didn't have 3.0 in mind for this suggestion, since it's in feature freeze last I heard.
linking discussion from https://contributors.scala-lang.org/t/implement-keyword-instead-of-override/4035