lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

implements keyword #139

Open oscar-broman opened 4 years ago

oscar-broman commented 4 years ago

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 = ???
}
kubukoz commented 4 years ago

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:

kubukoz commented 4 years ago

@bishabosha is there something I can do to help make this happen?

smarter commented 4 years ago

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)

kubukoz commented 4 years ago

Understood, maybe in a future release then :)

oscar-broman commented 4 years ago

I didn't have 3.0 in mind for this suggestion, since it's in feature freeze last I heard.

bishabosha commented 4 years ago

linking discussion from https://contributors.scala-lang.org/t/implement-keyword-instead-of-override/4035