-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Classes can't have an unfulfilled self type with unimplemented methods #4252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Indeed, instantiating such classes is forbidden later by the spec on
scala> trait Bar { def bar: Int }
defined trait Bar
scala> class Foo { self : Bar => }
defined class Foo
scala> new Foo
<console>:13: error: class Foo cannot be instantiated because it does not conform to its self-type Foo with Bar
new Foo
^ Not that I see the point of this behavior, but I'd default to following Scalac. |
But you can instantiate it as an anonymous class or extend it: scala> new Foo with Bar { def bar: Int = 1 }
res0: Foo with Bar = $anon$1@6002e944
scala> class Bat extends Foo with Bar { def bar: Int = 1 }
defined class Bat
scala> new Bat
res1: Bat = Bat@5dcf0772 So there is a real use case |
To clarify: I mean, one could just require that the class is marked abstract and support the same use cases. |
Gitter isn't sure either, but it seems this might have been discussed and left as-is: https://gitter.im/scala/contributors?at=5ac65cac27c509a774df5374 |
After discussion in the meeting, we decided to support the Scala 2 behavior under -language:Scala2, and keep the current behavior otherwise. |
FWIW, this compiles without error since #8332, both with and without -language:Scala2. |
It is allowed in Scalac
The text was updated successfully, but these errors were encountered: