scala/scala3

Non-abstract class that doesn't conform its self-type

Closed this issue · 4 comments

I'm not sure if it's an issue, but it seems unobvious, at least

Compiler version

2.13.x - 3.5.0-RC1 inclusive

Minimized example

consider this snippet

class Foo {
  self: Bar => 
}

trait Bar

val foo = Foo() //  Foo does not conform to its self type Bar; cannot be instantiated

an error is emitted only for the val foo = line, but not at the class definition
one would expect a non-abstract class to be directly instantiable

Adding the mixin val foo = new Foo with Bar is indeed still needed for instantiation, see self-types for more details.
I think this is not an issue, there is at least nothing in the spec indicating otherwise to my knowledge.
Perhaps we could emit a warning when declaring non-abstract classes requiring later mixins though.

Seems like a second opinion on whether it's worth adding a warning for this would be useful.

@sjrd for example, would you have an opinion about that?

@mbovel I actually stumbled on this last week:

// todo later: check that
// 1. If class is non-abstract, it is instantiatable:
// - self type is s supertype of own type
// - all type members have consistent bounds

I believe it is not specified that a non-abstract class should be instantiatable, there is little motivation for checking this.