Implement keyword (instead of override)

I don’t think that should be legal for the same reason that it’s illegal without the implements:

scala> :pa -raw
// Entering paste mode (ctrl-D to finish)

trait A { def name: String }
trait B extends A { def name = "Alice" }
trait C extends A { def name = "Bob" }
class D extends B with C

// Exiting paste mode, now interpreting.


class D extends B with C
      ^
<pastie>:4: error: class D inherits conflicting members:
  def name: String (defined in trait B) and
  def name: String (defined in trait C)
  (note: this can be resolved by declaring an `override` in class D.)
There were compilation errors!
3 Likes

Something like that?

Parent Modifier Outcome
abstract override compile error
abstract implement ok
abstract none compile error
concrete override ok
concrete implement compile error
concrete none compile error
absent override compile error
absent implement compile error
absent none ok
4 Likes

how about

Parent\Modifier none implement override
absent OK warn error
abstract warn OK warn
concrete error warn OK

?

3 Likes

Yeah sorry your layout makes more sense - I tend to use decision tables by default because I can then automatically turn them in property based tests, but that made little sense here.

I’m personally not very fussed about the distinction between warn and error - all my builds have fatal warnings enabled. I’m not 100% sure I see the logic though: what makes you go from warning to error? In the first line, for example, both “bad” cases feel equally bad (or benign) to me.

2 Likes

Oh, that’s wonderful. Thank you and @nrinaudo for outlining it.

For comparison this is what the situation is today, in Scala 2:

Parent\Modifier none implement override
absent OK (n/a) error
abstract OK (n/a) OK
concrete error (n/a) OK

To me the symmetry is very compelling! Both that:

  • there is a missing modifier in the language, and
  • the grey warning barrier between the OK states and the error states.
6 Likes

Thank you for all the replies, and sorry I didn’t engage more in the discussion. This last table looks very nice indeed, and warnings should suffice in most cases.

1 Like