Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

implements keyword #139

Open
oscar-broman opened this issue Sep 17, 2020 · 6 comments
Open

implements keyword #139

oscar-broman opened this issue Sep 17, 2020 · 6 comments

Comments

@oscar-broman
Copy link

oscar-broman commented Sep 17, 2020

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
Copy link

kubukoz commented Sep 18, 2020

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

@kubukoz
Copy link

kubukoz commented Sep 18, 2020

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

@smarter
Copy link
Member

smarter commented Sep 18, 2020

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
Copy link

kubukoz commented Sep 18, 2020

Understood, maybe in a future release then :)

@oscar-broman
Copy link
Author

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

@bishabosha
Copy link
Member

bishabosha commented Sep 18, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants